Bug 1168903 part 2: Use Move() instead of nsSMILValue::Swap() to populate outparams from temp variables in SMIL functions. r=birtles

This commit is contained in:
Daniel Holbert 2015-05-29 13:10:41 -07:00
parent 0df96b945e
commit dfc8e242f9
13 changed files with 41 additions and 38 deletions

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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

View File

@ -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<nsAString*>(val.mU.mPtr) = aStr;
aValue.Swap(val);
aValue = Move(val);
aPreventCachingOfSandwich = false;
return NS_OK;
}

View File

@ -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<nsAString*>(val.mU.mPtr) = aStr;
aValue.Swap(val);
aValue = Move(val);
aPreventCachingOfSandwich = false;
return NS_OK;
}

View File

@ -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<nsSVGViewBoxRect*>(val.mU.mPtr) = viewBox;
aValue.Swap(val);
aValue = Move(val);
aPreventCachingOfSandwich = false;
return NS_OK;