Changeset 143076 in webkit


Ignore:
Timestamp:
Feb 15, 2013 5:39:19 PM (11 years ago)
Author:
akling@apple.com
Message:

Calling DOM Element.attributes shouldn't force creation of ElementData.
<http://webkit.org/b/109976>

Reviewed by Darin Adler.

Don't create ElementData for an Element unnecessarily just because someone calls .attributes on it.
Previously, JS like this would create empty ElementData when 'element' has no attributes:

for (i = 0; i < element.attributes.length; ++i)

doStuff(element.attributes[i]);

Make NamedNodeMap::length() short-circuit and return 0 if !Element::hasAttributes().

  • dom/Element.cpp:

(WebCore::Element::attributes):

  • dom/NamedNodeMap.cpp:

(WebCore::NamedNodeMap::length):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r143075 r143076  
     12013-02-15  Andreas Kling  <akling@apple.com>
     2
     3        Calling DOM Element.attributes shouldn't force creation of ElementData.
     4        <http://webkit.org/b/109976>
     5
     6        Reviewed by Darin Adler.
     7
     8        Don't create ElementData for an Element unnecessarily just because someone calls .attributes on it.
     9        Previously, JS like this would create empty ElementData when 'element' has no attributes:
     10
     11            for (i = 0; i < element.attributes.length; ++i)
     12                doStuff(element.attributes[i]);
     13
     14        Make NamedNodeMap::length() short-circuit and return 0 if !Element::hasAttributes().
     15
     16        * dom/Element.cpp:
     17        (WebCore::Element::attributes):
     18        * dom/NamedNodeMap.cpp:
     19        (WebCore::NamedNodeMap::length):
     20
    1212013-02-15  Kentaro Hara  <haraken@chromium.org>
    222
  • trunk/Source/WebCore/dom/Element.cpp

    r143054 r143076  
    314314NamedNodeMap* Element::attributes() const
    315315{
    316     ensureElementDataWithSynchronizedAttributes();
    317316    ElementRareData* rareData = const_cast<Element*>(this)->ensureElementRareData();
    318317    if (NamedNodeMap* attributeMap = rareData->attributeMap())
  • trunk/Source/WebCore/dom/NamedNodeMap.cpp

    r141300 r143076  
    111111size_t NamedNodeMap::length() const
    112112{
     113    if (!m_element->hasAttributes())
     114        return 0;
    113115    return m_element->attributeCount();
    114116}
Note: See TracChangeset for help on using the changeset viewer.