Bug 1359556 - Optimize cloneNode by preinitializing attribute and child arrays r=bz

Currently, attribute and child arrays (implemented in dom/base/nsAttrAndChildArray.h) start out empty. When cloning, the array ends up being resized multiple times in order to add the attributes and children that are being cloned from the original node. This would be quicker if the array was initialized to the correct size in the first place so that resizes are not necessary.

However, preallocating space for children is only necessary when performing a deep clone. Therefore, an additional parameter is being added to the Clone, CopyInnerTo, and CloneDocHelper methods to indicate whether preallocation of children should happen. Attributes are copied either way, so that part of the array is preallocated in both cases.

MozReview-Commit-ID: 3iVezeAKXnI
This commit is contained in:
Kirk Steuber
2017-04-20 12:57:48 -07:00
parent 5025f72ae8
commit 9386a2f3e1
175 changed files with 447 additions and 212 deletions

View File

@@ -810,7 +810,7 @@ HTMLImageElement::GetNaturalWidth(uint32_t* aNaturalWidth)
}
nsresult
HTMLImageElement::CopyInnerTo(Element* aDest)
HTMLImageElement::CopyInnerTo(Element* aDest, bool aPreallocateChildren)
{
bool destIsStatic = aDest->OwnerDoc()->IsStaticDocument();
auto dest = static_cast<HTMLImageElement*>(aDest);
@@ -818,7 +818,7 @@ HTMLImageElement::CopyInnerTo(Element* aDest)
CreateStaticImageClone(dest);
}
nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest, aPreallocateChildren);
if (NS_FAILED(rv)) {
return rv;
}