Changeset 109619 in webkit


Ignore:
Timestamp:
Mar 2, 2012 2:48:03 PM (12 years ago)
Author:
caio.oliveira@openbossa.org
Message:

Implement NamedNodeMap::setNamedItem() in terms of Element::setAttributeNode() instead of the other way round
https://bugs.webkit.org/show_bug.cgi?id=80188

Reviewed by Ryosuke Niwa.

Using setNamedItem() in setAttributeNode() implementation made us do unnecessary
checks like whether the element existed or whether the given node was an
attribute. So now setAttributeNode() do less work.

No new tests were added, functionality should be unchanged.

  • dom/Element.cpp:

(WebCore::Element::setAttributeNode):
(WebCore::Element::setAttributeNodeNS):

  • dom/Element.h:

(Element):
(WebCore::Element::attributes): We got rid of ensureUpdatedAttributes(), next in
line will be updatedAttributes().

  • dom/NamedNodeMap.cpp:

(WebCore::NamedNodeMap::setNamedItem):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r109612 r109619  
     12012-03-02  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
     2
     3        Implement NamedNodeMap::setNamedItem() in terms of Element::setAttributeNode() instead of the other way round
     4        https://bugs.webkit.org/show_bug.cgi?id=80188
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Using setNamedItem() in setAttributeNode() implementation made us do unnecessary
     9        checks like whether the element existed or whether the given node was an
     10        attribute. So now setAttributeNode() do less work.
     11
     12        No new tests were added, functionality should be unchanged.
     13
     14        * dom/Element.cpp:
     15        (WebCore::Element::setAttributeNode):
     16        (WebCore::Element::setAttributeNodeNS):
     17        * dom/Element.h:
     18        (Element):
     19        (WebCore::Element::attributes): We got rid of ensureUpdatedAttributes(), next in
     20        line will be updatedAttributes().
     21        * dom/NamedNodeMap.cpp:
     22        (WebCore::NamedNodeMap::setNamedItem):
     23
    1242012-03-02  SravanKumar Sandela  <ssandela@innominds.com>
    225
  • trunk/Source/WebCore/dom/Element.cpp

    r109585 r109619  
    13751375        return 0;
    13761376    }
    1377     return static_pointer_cast<Attr>(ensureUpdatedAttributes()->setNamedItem(attr, ec));
     1377
     1378    ElementAttributeData* attributeData = ensureUpdatedAttributeData();
     1379    Attribute* attribute = attr->attr();
     1380    size_t index = attributeData->getAttributeItemIndex(attribute->name());
     1381    Attribute* oldAttribute = index != notFound ? attributeData->attributeItem(index) : 0;
     1382    if (oldAttribute == attribute)
     1383        return attr; // we know about it already
     1384
     1385    // INUSE_ATTRIBUTE_ERR: Raised if node is an Attr that is already an attribute of another Element object.
     1386    // The DOM user must explicitly clone Attr nodes to re-use them in other elements.
     1387    if (attr->ownerElement()) {
     1388        ec = INUSE_ATTRIBUTE_ERR;
     1389        return 0;
     1390    }
     1391
     1392    RefPtr<Attr> oldAttr;
     1393    if (oldAttribute) {
     1394        oldAttr = oldAttribute->createAttrIfNeeded(this);
     1395        attributeData->replaceAttribute(index, attribute, this);
     1396    } else
     1397        attributeData->addAttribute(attribute, this);
     1398
     1399    return oldAttr.release();
    13781400}
    13791401
    13801402PassRefPtr<Attr> Element::setAttributeNodeNS(Attr* attr, ExceptionCode& ec)
    13811403{
    1382     if (!attr) {
    1383         ec = TYPE_MISMATCH_ERR;
    1384         return 0;
    1385     }
    1386     return static_pointer_cast<Attr>(ensureUpdatedAttributes()->setNamedItem(attr, ec));
     1404    return setAttributeNode(attr, ec);
    13871405}
    13881406
  • trunk/Source/WebCore/dom/Element.h

    r109585 r109619  
    229229
    230230    // For exposing to DOM only.
    231     NamedNodeMap* attributes() const { return ensureUpdatedAttributes(); }
    232 
    233     NamedNodeMap* ensureUpdatedAttributes() const;
     231    NamedNodeMap* attributes() const;
     232
    234233    NamedNodeMap* updatedAttributes() const;
    235234
     
    531530}
    532531
    533 inline NamedNodeMap* Element::ensureUpdatedAttributes() const
     532inline NamedNodeMap* Element::attributes() const
    534533{
    535534    updateInvalidAttributes();
  • trunk/Source/WebCore/dom/NamedNodeMap.cpp

    r109585 r109619  
    104104        return 0;
    105105    }
    106     Attr* attr = static_cast<Attr*>(node);
    107106
    108     Attribute* attribute = attr->attr();
    109     size_t index = m_attributeData.getAttributeItemIndex(attribute->name());
    110     Attribute* oldAttribute = index != notFound ? m_attributeData.attributeItem(index) : 0;
    111     if (oldAttribute == attribute)
    112         return node; // we know about it already
    113 
    114     // INUSE_ATTRIBUTE_ERR: Raised if node is an Attr that is already an attribute of another Element object.
    115     // The DOM user must explicitly clone Attr nodes to re-use them in other elements.
    116     if (attr->ownerElement()) {
    117         ec = INUSE_ATTRIBUTE_ERR;
    118         return 0;
    119     }
    120 
    121     RefPtr<Attr> oldAttr;
    122     if (oldAttribute) {
    123         oldAttr = oldAttribute->createAttrIfNeeded(m_element);
    124         m_attributeData.replaceAttribute(index, attribute, m_element);
    125     } else
    126         m_attributeData.addAttribute(attribute, m_element);
    127 
    128     return oldAttr.release();
     107    return m_element->setAttributeNode(static_cast<Attr*>(node), ec);
    129108}
    130109
Note: See TracChangeset for help on using the changeset viewer.