Changeset 102695 in webkit


Ignore:
Timestamp:
Dec 13, 2011 12:40:51 PM (12 years ago)
Author:
adamk@chromium.org
Message:

Reduce code duplication in Element::setAttribute methods
https://bugs.webkit.org/show_bug.cgi?id=74425

Reviewed by Ryosuke Niwa.

Two overloads of Element::setAttribute share almost all their code,
including tricky logic around updating the appropriate Attribute and
Attr objects and notifying the Inspector and MutationObservers.

This patch puts the common logic in a new setAttributeInternal method
which is called by the other two.

No new tests, refactoring only.

  • dom/Element.cpp:

(WebCore::Element::setAttribute):
(WebCore::Element::setAttributeInternal):

  • dom/Element.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r102691 r102695  
     12011-12-13  Adam Klein  <adamk@chromium.org>
     2
     3        Reduce code duplication in Element::setAttribute methods
     4        https://bugs.webkit.org/show_bug.cgi?id=74425
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Two overloads of Element::setAttribute share almost all their code,
     9        including tricky logic around updating the appropriate Attribute and
     10        Attr objects and notifying the Inspector and MutationObservers.
     11
     12        This patch puts the common logic in a new setAttributeInternal method
     13        which is called by the other two.
     14
     15        No new tests, refactoring only.
     16
     17        * dom/Element.cpp:
     18        (WebCore::Element::setAttribute):
     19        (WebCore::Element::setAttributeInternal):
     20        * dom/Element.h:
     21
    1222011-12-13  Brady Eidson  <beidson@apple.com>
    223
  • trunk/Source/WebCore/dom/Element.cpp

    r102423 r102695  
    636636    }
    637637
     638    const AtomicString& localName = shouldIgnoreAttributeCase(this) ? name.lower() : name;
     639
     640    // Allocate attribute map if necessary.
     641    Attribute* old = attributes(false)->getAttributeItem(localName, false);
     642    setAttributeInternal(old, old ? old->name() : QualifiedName(nullAtom, localName, nullAtom), value);
     643}
     644
     645void Element::setAttribute(const QualifiedName& name, const AtomicString& value, ExceptionCode&)
     646{
     647    // Allocate attribute map if necessary.
     648    Attribute* old = attributes(false)->getAttributeItem(name);
     649    setAttributeInternal(old, name, value);
     650}
     651
     652void Element::setAttributeInternal(Attribute* old, const QualifiedName& name, const AtomicString& value)
     653{
    638654#if ENABLE(INSPECTOR)
    639655    if (!isSynchronizingStyleAttribute())
     
    641657#endif
    642658
    643     const AtomicString& localName = shouldIgnoreAttributeCase(this) ? name.lower() : name;
    644     QualifiedName attributeName(nullAtom, localName, nullAtom);
    645    
    646     // Allocate attribute map if necessary.
    647     Attribute* old = attributes(false)->getAttributeItem(localName, false);
    648 
    649659    document()->incDOMTreeVersion();
    650 
    651 #if ENABLE(MUTATION_OBSERVERS)
    652     // The call to attributeChanged below may dispatch DOMSubtreeModified, so it's important to enqueue a MutationRecord now.
    653     if (!isSynchronizingStyleAttribute())
    654         enqueueAttributesMutationRecord(this, attributeName, old ? old->value() : nullAtom);
    655 #endif
    656 
    657     if (isIdAttributeName(old ? old->name() : attributeName))
    658         updateId(old ? old->value() : nullAtom, value);
    659 
    660     if (old && value.isNull())
    661         m_attributeMap->removeAttribute(old->name());
    662     else if (!old && !value.isNull())
    663         m_attributeMap->addAttribute(createAttribute(attributeName, value));
    664     else if (old && !value.isNull()) {
    665         if (Attr* attrNode = old->attr())
    666             attrNode->setValue(value);
    667         else
    668             old->setValue(value);
    669         attributeChanged(old);
    670     }
    671 
    672 #if ENABLE(INSPECTOR)
    673     if (!isSynchronizingStyleAttribute())
    674         InspectorInstrumentation::didModifyDOMAttr(document(), this, name, value);
    675 #endif
    676 }
    677 
    678 void Element::setAttribute(const QualifiedName& name, const AtomicString& value, ExceptionCode&)
    679 {
    680 #if ENABLE(INSPECTOR)
    681     if (!isSynchronizingStyleAttribute())
    682         InspectorInstrumentation::willModifyDOMAttr(document(), this);
    683 #endif
    684 
    685     document()->incDOMTreeVersion();
    686 
    687     // Allocate attribute map if necessary.
    688     Attribute* old = attributes(false)->getAttributeItem(name);
    689660
    690661#if ENABLE(MUTATION_OBSERVERS)
  • trunk/Source/WebCore/dom/Element.h

    r102081 r102695  
    396396    virtual bool childTypeAllowed(NodeType) const;
    397397
     398    void setAttributeInternal(Attribute* old, const QualifiedName&, const AtomicString& value);
    398399    virtual PassRefPtr<Attribute> createAttribute(const QualifiedName&, const AtomicString& value);
    399400   
Note: See TracChangeset for help on using the changeset viewer.