Bug 554687 patch 1: Add Swap() method for nsSMILValue. r=roc

This commit is contained in:
Daniel Holbert 2010-03-25 09:02:01 -07:00
Родитель 7193d8a001
Коммит 496a409aa7
2 изменённых файлов: 26 добавлений и 0 удалений

Просмотреть файл

@ -38,6 +38,7 @@
#include "nsSMILValue.h"
#include "nsDebug.h"
#include "prlog.h"
//----------------------------------------------------------------------
// Public methods
@ -84,6 +85,29 @@ nsSMILValue::operator==(const nsSMILValue& aVal) const
return mType == aVal.mType && mType->IsEqual(*this, aVal);
}
static inline void
CopyMemberData(nsSMILValue& aDest, const nsSMILValue& aSrc)
{
aDest.mType = aSrc.mType;
aDest.mU.mUint = aSrc.mU.mUint;
// Make sure the above assignments accounted for all the bits in nsSMILValue
PR_STATIC_ASSERT(sizeof(aDest) ==
sizeof(aDest.mType) + sizeof(aDest.mU.mUint));
}
void
nsSMILValue::Swap(nsSMILValue& aOther)
{
nsSMILValue tmp;
CopyMemberData(tmp, aOther); // tmp = aOther
CopyMemberData(aOther, *this); // aOther = this
CopyMemberData(*this, tmp); // this = tmp
// |tmp| is about to die -- we need to clear its mType, so that its
// destructor doesn't muck with the data we just transferred out of it.
tmp.mType = &nsSMILNullType::sSingleton;
}
nsresult
nsSMILValue::Add(const nsSMILValue& aValueToAdd, PRUint32 aCount)
{

Просмотреть файл

@ -68,6 +68,8 @@ public:
return (mType == &nsSMILNullType::sSingleton);
}
// Swaps the contents (mU & mType) of two nsSMILValue objects.
void Swap(nsSMILValue& aOther);
nsresult Add(const nsSMILValue& aValueToAdd, PRUint32 aCount = 1);
nsresult SandwichAdd(const nsSMILValue& aValueToAdd);
nsresult ComputeDistance(const nsSMILValue& aTo, double& aDistance) const;