From dfc8e242f9ae798f76c9edf04cca1cea9e60cb69 Mon Sep 17 00:00:00 2001 From: Daniel Holbert Date: Fri, 29 May 2015 13:10:41 -0700 Subject: [PATCH] Bug 1168903 part 2: Use Move() instead of nsSMILValue::Swap() to populate outparams from temp variables in SMIL functions. r=birtles --- dom/smil/nsSMILAnimationFunction.cpp | 8 ++++---- dom/smil/nsSMILCSSProperty.cpp | 6 ++++-- dom/smil/nsSMILValue.cpp | 13 ------------- dom/smil/nsSMILValue.h | 3 --- dom/svg/SVGAnimatedLengthList.cpp | 6 ++++-- dom/svg/SVGAnimatedNumberList.cpp | 6 ++++-- dom/svg/SVGAnimatedPathSegList.cpp | 6 ++++-- dom/svg/SVGAnimatedPointList.cpp | 6 ++++-- dom/svg/nsSVGAngle.cpp | 7 ++++--- dom/svg/nsSVGAnimatedTransformList.cpp | 4 +++- dom/svg/nsSVGClass.cpp | 6 ++++-- dom/svg/nsSVGString.cpp | 4 +++- dom/svg/nsSVGViewBox.cpp | 4 +++- 13 files changed, 41 insertions(+), 38 deletions(-) diff --git a/dom/smil/nsSMILAnimationFunction.cpp b/dom/smil/nsSMILAnimationFunction.cpp index c7d19db56b88..276a85f48b1d 100644 --- a/dom/smil/nsSMILAnimationFunction.cpp +++ b/dom/smil/nsSMILAnimationFunction.cpp @@ -4,8 +4,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "mozilla/dom/SVGAnimationElement.h" #include "nsSMILAnimationFunction.h" + +#include "mozilla/dom/SVGAnimationElement.h" +#include "mozilla/Move.h" #include "nsISMILAttr.h" #include "nsSMILParserUtils.h" #include "nsSMILNullType.h" @@ -267,9 +269,7 @@ nsSMILAnimationFunction::ComposeResult(const nsISMILAttr& aSMILAttr, // If additive animation isn't required or isn't supported, set the value. if (!isAdditive || NS_FAILED(aResult.SandwichAdd(result))) { - aResult.Swap(result); - // Note: The old value of aResult is now in |result|, and it will get - // cleaned up when |result| goes out of scope, when this function returns. + aResult = Move(result); } } diff --git a/dom/smil/nsSMILCSSProperty.cpp b/dom/smil/nsSMILCSSProperty.cpp index 5d42c8bf5df0..b0e6bc9e0ba7 100644 --- a/dom/smil/nsSMILCSSProperty.cpp +++ b/dom/smil/nsSMILCSSProperty.cpp @@ -7,11 +7,13 @@ /* representation of a SMIL-animatable CSS property on an element */ #include "nsSMILCSSProperty.h" + +#include "mozilla/dom/Element.h" +#include "mozilla/Move.h" #include "nsSMILCSSValueType.h" #include "nsSMILValue.h" #include "nsComputedDOMStyle.h" #include "nsCSSProps.h" -#include "mozilla/dom/Element.h" #include "nsIDOMElement.h" #include "nsIDocument.h" @@ -81,7 +83,7 @@ nsSMILCSSProperty::GetBaseValue() const // In either case, just return a dummy value (initialized with the right // type, so as not to indicate failure). nsSMILValue tmpVal(&nsSMILCSSValueType::sSingleton); - baseValue.Swap(tmpVal); + Swap(baseValue, tmpVal); return baseValue; } diff --git a/dom/smil/nsSMILValue.cpp b/dom/smil/nsSMILValue.cpp index 134d48e4d872..cd881b0b016d 100644 --- a/dom/smil/nsSMILValue.cpp +++ b/dom/smil/nsSMILValue.cpp @@ -82,19 +82,6 @@ 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::Singleton(); -} - nsresult nsSMILValue::Add(const nsSMILValue& aValueToAdd, uint32_t aCount) { diff --git a/dom/smil/nsSMILValue.h b/dom/smil/nsSMILValue.h index da5bcd9f050e..c0998d61dbe8 100644 --- a/dom/smil/nsSMILValue.h +++ b/dom/smil/nsSMILValue.h @@ -49,9 +49,6 @@ public: return (mType == nsSMILNullType::Singleton()); } - // Swaps the member data (mU & mPtr) of |this| with |aOther| - void Swap(nsSMILValue& aOther); - nsresult Add(const nsSMILValue& aValueToAdd, uint32_t aCount = 1); nsresult SandwichAdd(const nsSMILValue& aValueToAdd); nsresult ComputeDistance(const nsSMILValue& aTo, double& aDistance) const; diff --git a/dom/svg/SVGAnimatedLengthList.cpp b/dom/svg/SVGAnimatedLengthList.cpp index a759329d8abc..91702a16b416 100644 --- a/dom/svg/SVGAnimatedLengthList.cpp +++ b/dom/svg/SVGAnimatedLengthList.cpp @@ -5,7 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "SVGAnimatedLengthList.h" + #include "DOMSVGAnimatedLengthList.h" +#include "mozilla/Move.h" #include "nsSVGElement.h" #include "nsSVGAttrTearoffTable.h" #include "nsSMILValue.h" @@ -138,7 +140,7 @@ SVGAnimatedLengthList:: nsresult rv = llai->SetValueFromString(aStr); if (NS_SUCCEEDED(rv)) { llai->SetInfo(mElement, mAxis, mCanZeroPadList); - aValue.Swap(val); + aValue = Move(val); // If any of the lengths in the list depend on their context, then we must // prevent caching of the entire animation sandwich. This is because the @@ -181,7 +183,7 @@ SVGAnimatedLengthList::SMILAnimatedLengthList::GetBaseValue() const nsresult rv = llai->CopyFrom(mVal->mBaseVal); if (NS_SUCCEEDED(rv)) { llai->SetInfo(mElement, mAxis, mCanZeroPadList); - val.Swap(tmp); + val = Move(tmp); } return val; } diff --git a/dom/svg/SVGAnimatedNumberList.cpp b/dom/svg/SVGAnimatedNumberList.cpp index 7e566a0d33dd..9be7ffadd80b 100644 --- a/dom/svg/SVGAnimatedNumberList.cpp +++ b/dom/svg/SVGAnimatedNumberList.cpp @@ -5,7 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "SVGAnimatedNumberList.h" + #include "DOMSVGAnimatedNumberList.h" +#include "mozilla/Move.h" #include "nsSVGElement.h" #include "nsSVGAttrTearoffTable.h" #include "nsSMILValue.h" @@ -138,7 +140,7 @@ SVGAnimatedNumberList:: nsresult rv = nlai->SetValueFromString(aStr); if (NS_SUCCEEDED(rv)) { nlai->SetInfo(mElement); - aValue.Swap(val); + aValue = Move(val); } aPreventCachingOfSandwich = false; return rv; @@ -157,7 +159,7 @@ SVGAnimatedNumberList::SMILAnimatedNumberList::GetBaseValue() const nsresult rv = nlai->CopyFrom(mVal->mBaseVal); if (NS_SUCCEEDED(rv)) { nlai->SetInfo(mElement); - val.Swap(tmp); + Swap(val, tmp); } return val; } diff --git a/dom/svg/SVGAnimatedPathSegList.cpp b/dom/svg/SVGAnimatedPathSegList.cpp index 5f3f7a0da3b0..4f07d20404d6 100644 --- a/dom/svg/SVGAnimatedPathSegList.cpp +++ b/dom/svg/SVGAnimatedPathSegList.cpp @@ -5,7 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "SVGAnimatedPathSegList.h" + #include "DOMSVGPathSegList.h" +#include "mozilla/Move.h" #include "nsSVGElement.h" #include "nsSVGAttrTearoffTable.h" #include "nsSMILValue.h" @@ -160,7 +162,7 @@ SVGAnimatedPathSegList:: nsresult rv = list->SetValueFromString(aStr); if (NS_SUCCEEDED(rv)) { list->SetElement(mElement); - aValue.Swap(val); + aValue = Move(val); } aPreventCachingOfSandwich = false; return rv; @@ -179,7 +181,7 @@ SVGAnimatedPathSegList::SMILAnimatedPathSegList::GetBaseValue() const nsresult rv = list->CopyFrom(mVal->mBaseVal); if (NS_SUCCEEDED(rv)) { list->SetElement(mElement); - val.Swap(tmp); + val = Move(tmp); } return val; } diff --git a/dom/svg/SVGAnimatedPointList.cpp b/dom/svg/SVGAnimatedPointList.cpp index c411b53b891d..13031901d77a 100644 --- a/dom/svg/SVGAnimatedPointList.cpp +++ b/dom/svg/SVGAnimatedPointList.cpp @@ -5,7 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "SVGAnimatedPointList.h" + #include "DOMSVGPointList.h" +#include "mozilla/Move.h" #include "nsSVGElement.h" #include "nsSVGAttrTearoffTable.h" #include "nsSMILValue.h" @@ -163,7 +165,7 @@ SVGAnimatedPointList:: nsresult rv = list->SetValueFromString(aStr); if (NS_SUCCEEDED(rv)) { list->SetInfo(mElement); - aValue.Swap(val); + aValue = Move(val); } aPreventCachingOfSandwich = false; return rv; @@ -182,7 +184,7 @@ SVGAnimatedPointList::SMILAnimatedPointList::GetBaseValue() const nsresult rv = list->CopyFrom(mVal->mBaseVal); if (NS_SUCCEEDED(rv)) { list->SetInfo(mElement); - val.Swap(tmp); + Swap(val, tmp); } return val; } diff --git a/dom/svg/nsSVGAngle.cpp b/dom/svg/nsSVGAngle.cpp index 15a9301ac15f..2c3c5f94cd36 100644 --- a/dom/svg/nsSVGAngle.cpp +++ b/dom/svg/nsSVGAngle.cpp @@ -4,10 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "mozilla/ArrayUtils.h" - #include "nsSVGAngle.h" + +#include "mozilla/ArrayUtils.h" #include "mozilla/dom/SVGMarkerElement.h" +#include "mozilla/Move.h" #include "nsContentUtils.h" // NS_ENSURE_FINITE #include "nsSMILValue.h" #include "nsSVGAttrTearoffTable.h" @@ -383,7 +384,7 @@ nsSVGAngle::SMILOrient::ValueFromString(const nsAString& aStr, val.mU.mOrient.mUnit = unitType; val.mU.mOrient.mOrientType = SVG_MARKER_ORIENT_ANGLE; } - aValue.Swap(val); + aValue = Move(val); aPreventCachingOfSandwich = false; return NS_OK; diff --git a/dom/svg/nsSVGAnimatedTransformList.cpp b/dom/svg/nsSVGAnimatedTransformList.cpp index 1da21c0fc863..dd4d550e5f40 100644 --- a/dom/svg/nsSVGAnimatedTransformList.cpp +++ b/dom/svg/nsSVGAnimatedTransformList.cpp @@ -5,8 +5,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsSVGAnimatedTransformList.h" + #include "mozilla/dom/SVGAnimatedTransformList.h" #include "mozilla/dom/SVGAnimationElement.h" +#include "mozilla/Move.h" #include "nsCharSeparatedTokenizer.h" #include "nsSVGTransform.h" #include "nsSMILValue.h" @@ -248,7 +250,7 @@ nsSVGAnimatedTransformList::SMILAnimatedTransformList::ParseValue( } // Success! Populate our outparam with parsed value. - aResult.Swap(val); + aResult = Move(val); } int32_t diff --git a/dom/svg/nsSVGClass.cpp b/dom/svg/nsSVGClass.cpp index 826fa0d0886b..bb114b9a8629 100644 --- a/dom/svg/nsSVGClass.cpp +++ b/dom/svg/nsSVGClass.cpp @@ -5,10 +5,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsSVGClass.h" + +#include "mozilla/dom/SVGAnimatedString.h" +#include "mozilla/Move.h" #include "nsSVGElement.h" #include "nsSMILValue.h" #include "SMILStringType.h" -#include "mozilla/dom/SVGAnimatedString.h" using namespace mozilla; using namespace mozilla::dom; @@ -130,7 +132,7 @@ nsSVGClass::SMILString::ValueFromString(const nsAString& aStr, nsSMILValue val(SMILStringType::Singleton()); *static_cast(val.mU.mPtr) = aStr; - aValue.Swap(val); + aValue = Move(val); aPreventCachingOfSandwich = false; return NS_OK; } diff --git a/dom/svg/nsSVGString.cpp b/dom/svg/nsSVGString.cpp index 041e013de16e..7c3de686808d 100644 --- a/dom/svg/nsSVGString.cpp +++ b/dom/svg/nsSVGString.cpp @@ -5,6 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsSVGString.h" + +#include "mozilla/Move.h" #include "nsSVGAttrTearoffTable.h" #include "nsSMILValue.h" #include "SMILStringType.h" @@ -110,7 +112,7 @@ nsSVGString::SMILString::ValueFromString(const nsAString& aStr, nsSMILValue val(SMILStringType::Singleton()); *static_cast(val.mU.mPtr) = aStr; - aValue.Swap(val); + aValue = Move(val); aPreventCachingOfSandwich = false; return NS_OK; } diff --git a/dom/svg/nsSVGViewBox.cpp b/dom/svg/nsSVGViewBox.cpp index ff11939b9bd6..61e345a37fec 100644 --- a/dom/svg/nsSVGViewBox.cpp +++ b/dom/svg/nsSVGViewBox.cpp @@ -5,6 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsSVGViewBox.h" + +#include "mozilla/Move.h" #include "nsCharSeparatedTokenizer.h" #include "nsSMILValue.h" #include "nsTextFormatter.h" @@ -300,7 +302,7 @@ nsSVGViewBox::SMILViewBox } nsSMILValue val(&SVGViewBoxSMILType::sSingleton); *static_cast(val.mU.mPtr) = viewBox; - aValue.Swap(val); + aValue = Move(val); aPreventCachingOfSandwich = false; return NS_OK;