From ec7ac1b850463295c5f34cff8f96ee6d54d9c20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 20 Jun 2023 19:11:18 +0000 Subject: [PATCH] Bug 1839485 - Minor string improvements in custom element reactions. r=edgar We're atomizing to turn into a string again which is wasteful. Differential Revision: https://phabricator.services.mozilla.com/D181552 --- dom/base/Element.cpp | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index fb15252cc0ac..80531ef76911 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -2617,25 +2617,24 @@ nsresult Element::SetAttrAndNotify( MOZ_ASSERT(definition, "Should have a valid CustomElementDefinition"); if (definition->IsInObservedAttributeList(aName)) { - RefPtr oldValueAtom; - if (oldValue) { - oldValueAtom = oldValue->GetAsAtom(); - } else { - // If there is no old value, get the value of the uninitialized - // attribute that was swapped with aParsedValue. - oldValueAtom = aParsedValue.GetAsAtom(); - } - RefPtr newValueAtom = valueForAfterSetAttr.GetAsAtom(); nsAutoString ns; nsNameSpaceManager::GetInstance()->GetNameSpaceURI(aNamespaceID, ns); LifecycleCallbackArgs args; - args.mName = nsDependentAtomString(aName); - args.mOldValue = (aModType == MutationEvent_Binding::ADDITION - ? VoidString() - : nsDependentAtomString(oldValueAtom)); - args.mNewValue = nsDependentAtomString(newValueAtom); - args.mNamespaceURI = (ns.IsEmpty() ? VoidString() : ns); + aName->ToString(args.mName); + if (aModType == MutationEvent_Binding::ADDITION) { + args.mOldValue = VoidString(); + } else { + if (oldValue) { + oldValue->ToString(args.mOldValue); + } else { + // If there is no old value, get the value of the uninitialized + // attribute that was swapped with aParsedValue. + aParsedValue.ToString(args.mOldValue); + } + } + valueForAfterSetAttr.ToString(args.mNewValue); + args.mNamespaceURI = ns.IsEmpty() ? VoidString() : ns; nsContentUtils::EnqueueLifecycleCallback( ElementCallbackType::eAttributeChanged, this, args, definition); @@ -2812,10 +2811,10 @@ void Element::OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName, nsAutoString value(aValue.String()); LifecycleCallbackArgs args; - args.mName = nsDependentAtomString(aName); + aName->ToString(args.mName); args.mOldValue = value; args.mNewValue = value; - args.mNamespaceURI = (ns.IsEmpty() ? VoidString() : ns); + args.mNamespaceURI = ns.IsEmpty() ? VoidString() : ns; nsContentUtils::EnqueueLifecycleCallback( ElementCallbackType::eAttributeChanged, this, args, definition); @@ -2903,18 +2902,14 @@ nsresult Element::UnsetAttr(int32_t aNameSpaceID, nsAtom* aName, bool aNotify) { if (data && data->mState == CustomElementData::State::eCustom) { CustomElementDefinition* definition = data->GetCustomElementDefinition(); MOZ_ASSERT(definition, "Should have a valid CustomElementDefinition"); - if (definition->IsInObservedAttributeList(aName)) { nsAutoString ns; nsNameSpaceManager::GetInstance()->GetNameSpaceURI(aNameSpaceID, ns); - - RefPtr oldValueAtom = oldValue.GetAsAtom(); LifecycleCallbackArgs args; - args.mName = nsDependentAtomString(aName); - args.mOldValue = nsDependentAtomString(oldValueAtom); + aName->ToString(args.mName); + oldValue.ToString(args.mOldValue); args.mNewValue = VoidString(); - args.mNamespaceURI = (ns.IsEmpty() ? VoidString() : ns); - + args.mNamespaceURI = ns.IsEmpty() ? VoidString() : ns; nsContentUtils::EnqueueLifecycleCallback( ElementCallbackType::eAttributeChanged, this, args, definition); }