Bug 1824933 - Avoid some copying in SVGLengthList and co. r=longsonr

Differential Revision: https://phabricator.services.mozilla.com/D174371
This commit is contained in:
Emilio Cobos Álvarez 2023-04-10 15:12:23 +00:00
Родитель bcab917ffe
Коммит c1830bc272
10 изменённых файлов: 21 добавлений и 55 удалений

Просмотреть файл

@ -20,10 +20,7 @@ using namespace dom;
nsresult SVGAnimatedLengthList::SetBaseValueString(const nsAString& aValue) {
SVGLengthList newBaseValue;
nsresult rv = newBaseValue.SetValueFromString(aValue);
if (NS_FAILED(rv)) {
return rv;
}
MOZ_TRY(newBaseValue.SetValueFromString(aValue));
DOMSVGAnimatedLengthList* domWrapper =
DOMSVGAnimatedLengthList::GetDOMWrapperIfExists(this);
@ -39,14 +36,8 @@ nsresult SVGAnimatedLengthList::SetBaseValueString(const nsAString& aValue) {
// We don't need to call DidChange* here - we're only called by
// SVGElement::ParseAttribute under Element::SetAttr,
// which takes care of notifying.
rv = mBaseVal.CopyFrom(newBaseValue);
if (NS_FAILED(rv) && domWrapper) {
// Attempting to increase mBaseVal's length failed - reduce domWrapper
// back to the same length:
domWrapper->InternalBaseValListWillChangeTo(mBaseVal);
}
return rv;
mBaseVal.SwapWith(newBaseValue);
return NS_OK;
}
void SVGAnimatedLengthList::ClearBaseValue(uint32_t aAttrEnum) {

Просмотреть файл

@ -19,10 +19,7 @@ namespace mozilla {
nsresult SVGAnimatedNumberList::SetBaseValueString(const nsAString& aValue) {
SVGNumberList newBaseValue;
nsresult rv = newBaseValue.SetValueFromString(aValue);
if (NS_FAILED(rv)) {
return rv;
}
MOZ_TRY(newBaseValue.SetValueFromString(aValue));
DOMSVGAnimatedNumberList* domWrapper =
DOMSVGAnimatedNumberList::GetDOMWrapperIfExists(this);
@ -40,13 +37,8 @@ nsresult SVGAnimatedNumberList::SetBaseValueString(const nsAString& aValue) {
// which takes care of notifying.
mIsBaseSet = true;
rv = mBaseVal.CopyFrom(newBaseValue);
if (NS_FAILED(rv) && domWrapper) {
// Attempting to increase mBaseVal's length failed - reduce domWrapper
// back to the same length:
domWrapper->InternalBaseValListWillChangeTo(mBaseVal);
}
return rv;
mBaseVal.SwapWith(newBaseValue);
return NS_OK;
}
void SVGAnimatedNumberList::ClearBaseValue(uint32_t aAttrEnum) {

Просмотреть файл

@ -25,7 +25,6 @@ nsresult SVGAnimatedPathSegList::SetBaseValueString(const nsAString& aValue) {
// The spec says that the path data is parsed and accepted up to the first
// error encountered, so we don't return early if an error occurs. However,
// we do want to throw any error code from setAttribute if there's a problem.
nsresult rv = newBaseValue.SetValueFromString(aValue);
// We must send these notifications *before* changing mBaseVal! Our baseVal's
@ -56,20 +55,7 @@ nsresult SVGAnimatedPathSegList::SetBaseValueString(const nsAString& aValue) {
// SVGElement::ParseAttribute under Element::SetAttr,
// which takes care of notifying.
nsresult rv2 = mBaseVal.CopyFrom(newBaseValue);
if (NS_FAILED(rv2)) {
if (StaticPrefs::dom_svg_pathSeg_enabled()) {
// Attempting to increase mBaseVal's length failed (mBaseVal is left
// unmodified). We MUST keep any DOM wrappers in sync:
if (baseValWrapper) {
baseValWrapper->InternalListWillChangeTo(mBaseVal);
}
if (animValWrapper) {
animValWrapper->InternalListWillChangeTo(mBaseVal);
}
}
return rv2;
}
mBaseVal.SwapWith(newBaseValue);
return rv;
}
@ -177,7 +163,7 @@ SMILValue SVGAnimatedPathSegList::SMILAnimatedPathSegList::GetBaseValue()
SMILValue val;
SMILValue tmp(SVGPathSegListSMILType::Singleton());
SVGPathDataAndInfo* list = static_cast<SVGPathDataAndInfo*>(tmp.mU.mPtr);
auto* list = static_cast<SVGPathDataAndInfo*>(tmp.mU.mPtr);
nsresult rv = list->CopyFrom(mVal->mBaseVal);
if (NS_SUCCEEDED(rv)) {
list->SetElement(mElement);

Просмотреть файл

@ -54,18 +54,7 @@ nsresult SVGAnimatedPointList::SetBaseValueString(const nsAString& aValue) {
// SVGElement::ParseAttribute under Element::SetAttr,
// which takes care of notifying.
nsresult rv2 = mBaseVal.CopyFrom(newBaseValue);
if (NS_FAILED(rv2)) {
// Attempting to increase mBaseVal's length failed (mBaseVal is left
// unmodified). We MUST keep any DOM wrappers in sync:
if (baseValWrapper) {
baseValWrapper->InternalListWillChangeTo(mBaseVal);
}
if (animValWrapper) {
animValWrapper->InternalListWillChangeTo(mBaseVal);
}
return rv2;
}
mBaseVal.SwapWith(newBaseValue);
return rv;
}
@ -165,7 +154,7 @@ SMILValue SVGAnimatedPointList::SMILAnimatedPointList::GetBaseValue() const {
SMILValue val;
SMILValue tmp(&SVGPointListSMILType::sSingleton);
SVGPointListAndInfo* list = static_cast<SVGPointListAndInfo*>(tmp.mU.mPtr);
auto* list = static_cast<SVGPointListAndInfo*>(tmp.mU.mPtr);
nsresult rv = list->CopyFrom(mVal->mBaseVal);
if (NS_SUCCEEDED(rv)) {
list->SetInfo(mElement);

Просмотреть файл

@ -56,7 +56,8 @@ nsresult SVGLengthList::SetValueFromString(const nsAString& aValue) {
if (tokenizer.separatorAfterCurrentToken()) {
return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
}
return CopyFrom(temp);
mLengths = std::move(temp.mLengths);
return NS_OK;
}
bool SVGLengthList::operator==(const SVGLengthList& rhs) const {

Просмотреть файл

@ -85,7 +85,10 @@ class SVGLengthList {
* This may fail on OOM if the internal capacity needs to be increased, in
* which case the list will be left unmodified.
*/
nsresult CopyFrom(const SVGLengthList& rhs);
nsresult CopyFrom(const SVGLengthList&);
void SwapWith(SVGLengthList& aOther) {
mLengths.SwapElements(aOther.mLengths);
}
SVGLength& operator[](uint32_t aIndex) { return mLengths[aIndex]; }

Просмотреть файл

@ -58,7 +58,8 @@ nsresult SVGNumberList::SetValueFromString(const nsAString& aValue) {
if (tokenizer.separatorAfterCurrentToken()) {
return NS_ERROR_DOM_SYNTAX_ERR; // trailing comma
}
return CopyFrom(temp);
mNumbers = std::move(temp.mNumbers);
return NS_OK;
}
} // namespace mozilla

Просмотреть файл

@ -84,6 +84,7 @@ class SVGNumberList {
* which case the list will be left unmodified.
*/
nsresult CopyFrom(const SVGNumberList& rhs);
void SwapWith(SVGNumberList& aRhs) { mNumbers.SwapElements(aRhs.mNumbers); }
float& operator[](uint32_t aIndex) { return mNumbers[aIndex]; }

Просмотреть файл

@ -213,6 +213,7 @@ class SVGPathData {
* which case the list will be left unmodified.
*/
nsresult CopyFrom(const SVGPathData& rhs);
void SwapWith(SVGPathData& aRhs) { mData.SwapElements(aRhs.mData); }
float& operator[](uint32_t aIndex) { return mData[aIndex]; }

Просмотреть файл

@ -81,6 +81,7 @@ class SVGPointList {
* which case the list will be left unmodified.
*/
nsresult CopyFrom(const SVGPointList& rhs);
void SwapWith(SVGPointList& aRhs) { mItems.SwapElements(aRhs.mItems); }
SVGPoint& operator[](uint32_t aIndex) { return mItems[aIndex]; }