Bug 1263486 part 1 - Add a move constructor and assignment operator to nsCSSValue draft
authorBrian Birtles <birtles@gmail.com>
Fri, 20 May 2016 09:09:28 +0900
changeset 368984 51d71a5b0b4abd917c50ec3123206ab93f200077
parent 368911 1806d405c8715949b39fa3a4fc142d14a60df590
child 368985 a6742b5a8537abff793cd87e37d741572abc880f
push id18687
push userbbirtles@mozilla.com
push dateFri, 20 May 2016 00:11:47 +0000
bugs1263486
milestone49.0a1
Bug 1263486 part 1 - Add a move constructor and assignment operator to nsCSSValue MozReview-Commit-ID: IgtvOuPqWge
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -211,16 +211,29 @@ nsCSSValue& nsCSSValue::operator=(const 
 {
   if (this != &aCopy) {
     Reset();
     new (this) nsCSSValue(aCopy);
   }
   return *this;
 }
 
+nsCSSValue&
+nsCSSValue::operator=(nsCSSValue&& aOther)
+{
+  MOZ_ASSERT(this != &aOther, "Self assigment with rvalue reference");
+
+  Reset();
+  mUnit = aOther.mUnit;
+  mValue = aOther.mValue;
+  aOther.mUnit = eCSSUnit_Null;
+
+  return *this;
+}
+
 bool nsCSSValue::operator==(const nsCSSValue& aOther) const
 {
   MOZ_ASSERT(mUnit != eCSSUnit_ListDep &&
              aOther.mUnit != eCSSUnit_ListDep &&
              mUnit != eCSSUnit_PairListDep &&
              aOther.mUnit != eCSSUnit_PairListDep,
              "don't use operator== with dependent lists");
 
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -421,19 +421,26 @@ public:
   nsCSSValue(Array* aArray, nsCSSUnit aUnit);
   explicit nsCSSValue(mozilla::css::URLValue* aValue);
   explicit nsCSSValue(mozilla::css::ImageValue* aValue);
   explicit nsCSSValue(nsCSSValueGradient* aValue);
   explicit nsCSSValue(nsCSSValueTokenStream* aValue);
   explicit nsCSSValue(mozilla::css::GridTemplateAreasValue* aValue);
   explicit nsCSSValue(mozilla::css::FontFamilyListRefCnt* aValue);
   nsCSSValue(const nsCSSValue& aCopy);
+  nsCSSValue(nsCSSValue&& aOther)
+    : mUnit(aOther.mUnit)
+    , mValue(aOther.mValue)
+  {
+    aOther.mUnit = eCSSUnit_Null;
+  }
   ~nsCSSValue() { Reset(); }
 
   nsCSSValue&  operator=(const nsCSSValue& aCopy);
+  nsCSSValue&  operator=(nsCSSValue&& aCopy);
   bool        operator==(const nsCSSValue& aOther) const;
 
   bool operator!=(const nsCSSValue& aOther) const
   {
     return !(*this == aOther);
   }
 
   // Enum for AppendToString's aValueSerialization argument.