Bug 1430951 - Avoid element name atomizing to improve performance of LookupCustomElementDefinition

Since we are dealing with the element (nodeInfo->LocalName() and NameAtom() are the same value), we could use nodeInfo->NameAtom() instead.

Tag UXP Issue #1344
This commit is contained in:
Gaming4JC 2020-01-25 09:14:03 -05:00 • committed by Roy Tam
commit 57da7a1935
7 changed files with 16 additions and 11 deletions

View file

@ -243,12 +243,11 @@ CustomElementRegistry::~CustomElementRegistry()
} }
CustomElementDefinition* CustomElementDefinition*
CustomElementRegistry::LookupCustomElementDefinition(const nsAString& aLocalName, CustomElementRegistry::LookupCustomElementDefinition(nsIAtom* aNameAtom,
nsIAtom* aTypeAtom) const nsIAtom* aTypeAtom) const
{ {
nsCOMPtr<nsIAtom> localNameAtom = NS_Atomize(aLocalName);
CustomElementDefinition* data = mCustomDefinitions.GetWeak(aTypeAtom); CustomElementDefinition* data = mCustomDefinitions.GetWeak(aTypeAtom);
if (data && data->mLocalName == localNameAtom) { if (data && data->mLocalName == aNameAtom) {
return data; return data;
} }

View file

@ -412,7 +412,7 @@ public:
* https://html.spec.whatwg.org/#look-up-a-custom-element-definition * https://html.spec.whatwg.org/#look-up-a-custom-element-definition
*/ */
CustomElementDefinition* LookupCustomElementDefinition( CustomElementDefinition* LookupCustomElementDefinition(
const nsAString& aLocalName, nsIAtom* aTypeAtom) const; nsIAtom* aNameAtom, nsIAtom* aTypeAtom) const;
CustomElementDefinition* LookupCustomElementDefinition( CustomElementDefinition* LookupCustomElementDefinition(
JSContext* aCx, JSObject *aConstructor) const; JSContext* aCx, JSObject *aConstructor) const;

View file

@ -9536,9 +9536,11 @@ nsContentUtils::TryToUpgradeElement(Element* aElement)
NodeInfo* nodeInfo = aElement->NodeInfo(); NodeInfo* nodeInfo = aElement->NodeInfo();
RefPtr<nsIAtom> typeAtom = RefPtr<nsIAtom> typeAtom =
aElement->GetCustomElementData()->GetCustomElementType(); aElement->GetCustomElementData()->GetCustomElementType();
MOZ_ASSERT(nodeInfo->NameAtom()->Equals(nodeInfo->LocalName()));
CustomElementDefinition* definition = CustomElementDefinition* definition =
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(), nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
nodeInfo->LocalName(), nodeInfo->NameAtom(),
nodeInfo->NamespaceID(), nodeInfo->NamespaceID(),
typeAtom); typeAtom);
if (definition) { if (definition) {
@ -9553,7 +9555,7 @@ nsContentUtils::TryToUpgradeElement(Element* aElement)
/* static */ CustomElementDefinition* /* static */ CustomElementDefinition*
nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc, nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc,
const nsAString& aLocalName, nsIAtom* aNameAtom,
uint32_t aNameSpaceID, uint32_t aNameSpaceID,
nsIAtom* aTypeAtom) nsIAtom* aTypeAtom)
{ {
@ -9577,7 +9579,7 @@ nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc,
return nullptr; return nullptr;
} }
return registry->LookupCustomElementDefinition(aLocalName, aTypeAtom); return registry->LookupCustomElementDefinition(aNameAtom, aTypeAtom);
} }
/* static */ void /* static */ void

View file

@ -2712,7 +2712,7 @@ public:
*/ */
static mozilla::dom::CustomElementDefinition* static mozilla::dom::CustomElementDefinition*
LookupCustomElementDefinition(nsIDocument* aDoc, LookupCustomElementDefinition(nsIDocument* aDoc,
const nsAString& aLocalName, nsIAtom* aNameAtom,
uint32_t aNameSpaceID, uint32_t aNameSpaceID,
nsIAtom* aTypeAtom); nsIAtom* aTypeAtom);

View file

@ -497,9 +497,11 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
if (data || !extension.IsEmpty()) { if (data || !extension.IsEmpty()) {
RefPtr<nsIAtom> typeAtom = extension.IsEmpty() ? tagAtom : NS_Atomize(extension); RefPtr<nsIAtom> typeAtom = extension.IsEmpty() ? tagAtom : NS_Atomize(extension);
cloneElem->SetCustomElementData(new CustomElementData(typeAtom)); cloneElem->SetCustomElementData(new CustomElementData(typeAtom));
MOZ_ASSERT(nodeInfo->NameAtom()->Equals(nodeInfo->LocalName()));
CustomElementDefinition* definition = CustomElementDefinition* definition =
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(), nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
nodeInfo->LocalName(), nodeInfo->NameAtom(),
nodeInfo->NamespaceID(), nodeInfo->NamespaceID(),
typeAtom); typeAtom);
if (definition) { if (definition) {

View file

@ -287,9 +287,10 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&&
CustomElementDefinition* definition = aDefinition; CustomElementDefinition* definition = aDefinition;
if (CustomElementRegistry::IsCustomElementEnabled() && isCustomElement && if (CustomElementRegistry::IsCustomElementEnabled() && isCustomElement &&
!definition) { !definition) {
MOZ_ASSERT(nodeInfo->NameAtom()->Equals(nodeInfo->LocalName()));
definition = definition =
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(), nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
nodeInfo->LocalName(), nodeInfo->NameAtom(),
nodeInfo->NamespaceID(), nodeInfo->NamespaceID(),
typeAtom); typeAtom);
} }

View file

@ -433,8 +433,9 @@ nsHtml5TreeOperation::CreateHTMLElement(
RefPtr<nsIAtom> typeAtom = RefPtr<nsIAtom> typeAtom =
isValue.IsEmpty() ? tagAtom : NS_Atomize(isValue); isValue.IsEmpty() ? tagAtom : NS_Atomize(isValue);
MOZ_ASSERT(nodeInfo->NameAtom()->Equals(nodeInfo->LocalName()));
definition = nsContentUtils::LookupCustomElementDefinition(document, definition = nsContentUtils::LookupCustomElementDefinition(document,
nodeInfo->LocalName(), nodeInfo->NamespaceID(), typeAtom); nodeInfo->NameAtom(), nodeInfo->NamespaceID(), typeAtom);
if (definition) { if (definition) {
willExecuteScript = true; willExecuteScript = true;