Bug 1168903 part 1: Give nsSMILValue a move constructor & move reassignment operator. r=birtles
authorDaniel Holbert <dholbert@cs.stanford.edu>
Fri, 29 May 2015 13:10:39 -0700
changeset 246327 24f1455af9f282ba0df1538fb550dbf6731e1c6e
parent 246326 213dcfe0e21d268c2127c44a2177fbd60a350776
child 246328 b779fae94e88a9f85be80dac30da4cb64e8fe277
push id60412
push userdholbert@mozilla.com
push dateFri, 29 May 2015 20:10:49 +0000
treeherdermozilla-inbound@b779fae94e88 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1168903
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1168903 part 1: Give nsSMILValue a move constructor & move reassignment operator. r=birtles
dom/smil/nsSMILValue.cpp
dom/smil/nsSMILValue.h
--- a/dom/smil/nsSMILValue.cpp
+++ b/dom/smil/nsSMILValue.cpp
@@ -39,16 +39,45 @@ nsSMILValue::operator=(const nsSMILValue
     DestroyAndReinit(aVal.mType);
   }
 
   mType->Assign(*this, aVal);
 
   return *this;
 }
 
+// Move constructor / reassignment operator:
+nsSMILValue::nsSMILValue(nsSMILValue&& aVal)
+  : mU(aVal.mU), // Copying union is only OK because we clear aVal.mType below.
+    mType(aVal.mType)
+{
+  // Leave aVal with a null type, so that it's safely destructible (and won't
+  // mess with anything referenced by its union, which we've copied).
+  aVal.mType = nsSMILNullType::Singleton();
+}
+
+nsSMILValue&
+nsSMILValue::operator=(nsSMILValue&& aVal)
+{
+  if (!IsNull()) {
+    // Clean up any data we're currently tracking.
+    DestroyAndCheckPostcondition();
+  }
+
+  // Copy the union (which could include a pointer to external memory) & mType:
+  mU = aVal.mU;
+  mType = aVal.mType;
+
+  // Leave aVal with a null type, so that it's safely destructible (and won't
+  // mess with anything referenced by its union, which we've now copied).
+  aVal.mType = nsSMILNullType::Singleton();
+
+  return *this;
+}
+
 bool
 nsSMILValue::operator==(const nsSMILValue& aVal) const
 {
   if (&aVal == this)
     return true;
 
   return mType == aVal.mType && mType->IsEqual(*this, aVal);
 }
--- a/dom/smil/nsSMILValue.h
+++ b/dom/smil/nsSMILValue.h
@@ -28,16 +28,20 @@ public:
 
   ~nsSMILValue()
   {
     mType->Destroy(*this);
   }
 
   const nsSMILValue& operator=(const nsSMILValue& aVal);
 
+  // Move constructor / reassignment operator:
+  nsSMILValue(nsSMILValue&& aVal);
+  nsSMILValue& operator=(nsSMILValue&& aVal);
+
   // Equality operators. These are allowed to be conservative (return false
   // more than you'd expect) - see comment above nsISMILType::IsEqual.
   bool operator==(const nsSMILValue& aVal) const;
   bool operator!=(const nsSMILValue& aVal) const {
     return !(*this == aVal);
   }
 
   bool IsNull() const