From 0136850d8bddd5261bdc1980fdb2f2b4eb4c8c9b Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Tue, 7 Jul 2015 11:27:03 -0700 Subject: [PATCH] Bug 1179282 - Use nsTArray::Assign instead of the assignment operator in dom/svg/. r=dholbert --- dom/svg/SVGLengthList.cpp | 4 +--- dom/svg/SVGMotionSMILType.cpp | 5 +---- dom/svg/SVGNumberList.cpp | 4 +--- dom/svg/SVGPathData.cpp | 4 +--- dom/svg/SVGPointList.cpp | 4 +--- dom/svg/SVGStringList.cpp | 4 +--- dom/svg/SVGTransformList.cpp | 4 +--- dom/svg/SVGTransformListSMILType.cpp | 9 +++------ 8 files changed, 10 insertions(+), 28 deletions(-) diff --git a/dom/svg/SVGLengthList.cpp b/dom/svg/SVGLengthList.cpp index b44de345ff28..0c5b7752e535 100644 --- a/dom/svg/SVGLengthList.cpp +++ b/dom/svg/SVGLengthList.cpp @@ -18,11 +18,9 @@ namespace mozilla { nsresult SVGLengthList::CopyFrom(const SVGLengthList& rhs) { - if (!mLengths.SetCapacity(rhs.Length(), fallible)) { - // Yes, we do want fallible alloc here + if (!mLengths.Assign(rhs.mLengths, fallible)) { return NS_ERROR_OUT_OF_MEMORY; } - mLengths = rhs.mLengths; return NS_OK; } diff --git a/dom/svg/SVGMotionSMILType.cpp b/dom/svg/SVGMotionSMILType.cpp index 1e6fb421a278..2e91d1774628 100644 --- a/dom/svg/SVGMotionSMILType.cpp +++ b/dom/svg/SVGMotionSMILType.cpp @@ -197,13 +197,10 @@ SVGMotionSMILType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const const MotionSegmentArray& srcArr = ExtractMotionSegmentArray(aSrc); MotionSegmentArray& dstArr = ExtractMotionSegmentArray(aDest); - - // Ensure we have sufficient memory. - if (!dstArr.SetCapacity(srcArr.Length(), fallible)) { + if (!dstArr.Assign(srcArr, fallible)) { return NS_ERROR_OUT_OF_MEMORY; } - dstArr = srcArr; // Do the assignment. return NS_OK; } diff --git a/dom/svg/SVGNumberList.cpp b/dom/svg/SVGNumberList.cpp index c32f4a3b3115..2d0d37d45555 100644 --- a/dom/svg/SVGNumberList.cpp +++ b/dom/svg/SVGNumberList.cpp @@ -17,11 +17,9 @@ namespace mozilla { nsresult SVGNumberList::CopyFrom(const SVGNumberList& rhs) { - if (!mNumbers.SetCapacity(rhs.Length(), fallible)) { - // Yes, we do want fallible alloc here + if (!mNumbers.Assign(rhs.mNumbers, fallible)) { return NS_ERROR_OUT_OF_MEMORY; } - mNumbers = rhs.mNumbers; return NS_OK; } diff --git a/dom/svg/SVGPathData.cpp b/dom/svg/SVGPathData.cpp index 39edc17351af..b43c796e12c2 100644 --- a/dom/svg/SVGPathData.cpp +++ b/dom/svg/SVGPathData.cpp @@ -34,11 +34,9 @@ static bool IsMoveto(uint16_t aSegType) nsresult SVGPathData::CopyFrom(const SVGPathData& rhs) { - if (!mData.SetCapacity(rhs.mData.Length(), fallible)) { - // Yes, we do want fallible alloc here + if (!mData.Assign(rhs.mData, fallible)) { return NS_ERROR_OUT_OF_MEMORY; } - mData = rhs.mData; return NS_OK; } diff --git a/dom/svg/SVGPointList.cpp b/dom/svg/SVGPointList.cpp index 425380553439..8cbc55148b7c 100644 --- a/dom/svg/SVGPointList.cpp +++ b/dom/svg/SVGPointList.cpp @@ -16,11 +16,9 @@ namespace mozilla { nsresult SVGPointList::CopyFrom(const SVGPointList& rhs) { - if (!SetCapacity(rhs.Length())) { - // Yes, we do want fallible alloc here + if (!mItems.Assign(rhs.mItems, fallible)) { return NS_ERROR_OUT_OF_MEMORY; } - mItems = rhs.mItems; return NS_OK; } diff --git a/dom/svg/SVGStringList.cpp b/dom/svg/SVGStringList.cpp index 0184bc1f7ee8..dc00bc5b883b 100644 --- a/dom/svg/SVGStringList.cpp +++ b/dom/svg/SVGStringList.cpp @@ -16,11 +16,9 @@ namespace mozilla { nsresult SVGStringList::CopyFrom(const SVGStringList& rhs) { - if (!mStrings.SetCapacity(rhs.Length(), fallible)) { - // Yes, we do want fallible alloc here + if (!mStrings.Assign(rhs.mStrings, fallible)) { return NS_ERROR_OUT_OF_MEMORY; } - mStrings = rhs.mStrings; mIsSet = true; return NS_OK; } diff --git a/dom/svg/SVGTransformList.cpp b/dom/svg/SVGTransformList.cpp index d37e79ce2275..c6c4eefafee9 100644 --- a/dom/svg/SVGTransformList.cpp +++ b/dom/svg/SVGTransformList.cpp @@ -43,11 +43,9 @@ SVGTransformList::CopyFrom(const SVGTransformList& rhs) nsresult SVGTransformList::CopyFrom(const nsTArray& aTransformArray) { - if (!mItems.SetCapacity(aTransformArray.Length(), fallible)) { - // Yes, we do want fallible alloc here + if (!mItems.Assign(aTransformArray, fallible)) { return NS_ERROR_OUT_OF_MEMORY; } - mItems = aTransformArray; return NS_OK; } diff --git a/dom/svg/SVGTransformListSMILType.cpp b/dom/svg/SVGTransformListSMILType.cpp index c74cd2084bab..40777b026bd4 100644 --- a/dom/svg/SVGTransformListSMILType.cpp +++ b/dom/svg/SVGTransformListSMILType.cpp @@ -48,12 +48,9 @@ SVGTransformListSMILType::Assign(nsSMILValue& aDest, const TransformArray* srcTransforms = static_cast(aSrc.mU.mPtr); TransformArray* dstTransforms = static_cast(aDest.mU.mPtr); - - // Before we assign, ensure we have sufficient memory - bool result = dstTransforms->SetCapacity(srcTransforms->Length(), fallible); - NS_ENSURE_TRUE(result,NS_ERROR_OUT_OF_MEMORY); - - *dstTransforms = *srcTransforms; + if (!dstTransforms->Assign(*srcTransforms, fallible)) { + return NS_ERROR_OUT_OF_MEMORY; + } return NS_OK; }