Bug 1263486 part 1 - Add a move constructor and assignment operator to nsCSSValue
MozReview-Commit-ID: IgtvOuPqWge
--- 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.