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

This commit is contained in:
Daniel Holbert 2010-03-26 12:22:54 -07:00
parent 1dd4df88b2
commit f2b8035cd9
2 changed files with 17 additions and 0 deletions

View File

@ -38,6 +38,7 @@
#include "nsSMILValue.h"
#include "nsDebug.h"
#include <string.h>
//----------------------------------------------------------------------
// Public methods
@ -84,6 +85,19 @@ nsSMILValue::operator==(const nsSMILValue& aVal) const
return mType == aVal.mType && mType->IsEqual(*this, aVal);
}
void
nsSMILValue::Swap(nsSMILValue& aOther)
{
nsSMILValue tmp;
memcpy(&tmp, &aOther, sizeof(nsSMILValue)); // tmp = aOther
memcpy(&aOther, this, sizeof(nsSMILValue)); // aOther = this
memcpy(this, &tmp, sizeof(nsSMILValue)); // 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)
{

View File

@ -68,6 +68,9 @@ public:
return (mType == &nsSMILNullType::sSingleton);
}
// Swaps the member data (mU & mPtr) of |this| with |aOther|
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;