Title: [110086] trunk/Source/WebCore
Revision
110086
Author
caio.olive...@openbossa.org
Date
2012-03-07 12:37:32 -0800 (Wed, 07 Mar 2012)

Log Message

Implement removeAttributeNode() in terms of ElementAttributeData instead of NamedNodeMap
https://bugs.webkit.org/show_bug.cgi?id=80522

Reviewed by Andreas Kling.

DOM methods exposed in Element and NamedNodeMap are now implemented in terms of
ElementAttributeData. A helper function takeAttribute() was added to increase
code sharing. Also removed some unneeded methods.

* dom/Element.cpp:
(WebCore::Element::removeAttribute): Use ElementAttributeData function directly.
(WebCore::Element::removeAttributeNode): Get the index manually and use new
takeAttribute() directly.
* dom/Element.h:
(Element): Remove unused removeAttribute(unsigned index).
* dom/ElementAttributeData.cpp:
(WebCore::ElementAttributeData::takeAttribute): Like removeAttribute() but
returns a reference to old Attr.
(WebCore):
* dom/ElementAttributeData.h:
(ElementAttributeData):
* dom/NamedNodeMap.cpp:
(WebCore::NamedNodeMap::removeNamedItem): Avoid looking up the property twice by
getting the index directly from the name, instead of going through the qualified name.
* dom/NamedNodeMap.h: Remove now unused internal methods for removing attributes.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (110085 => 110086)


--- trunk/Source/WebCore/ChangeLog	2012-03-07 20:23:37 UTC (rev 110085)
+++ trunk/Source/WebCore/ChangeLog	2012-03-07 20:37:32 UTC (rev 110086)
@@ -1,3 +1,31 @@
+2012-03-07  Caio Marcelo de Oliveira Filho  <caio.olive...@openbossa.org>
+
+        Implement removeAttributeNode() in terms of ElementAttributeData instead of NamedNodeMap
+        https://bugs.webkit.org/show_bug.cgi?id=80522
+
+        Reviewed by Andreas Kling.
+
+        DOM methods exposed in Element and NamedNodeMap are now implemented in terms of
+        ElementAttributeData. A helper function takeAttribute() was added to increase
+        code sharing. Also removed some unneeded methods.
+
+        * dom/Element.cpp:
+        (WebCore::Element::removeAttribute): Use ElementAttributeData function directly.
+        (WebCore::Element::removeAttributeNode): Get the index manually and use new
+        takeAttribute() directly.
+        * dom/Element.h:
+        (Element): Remove unused removeAttribute(unsigned index).
+        * dom/ElementAttributeData.cpp:
+        (WebCore::ElementAttributeData::takeAttribute): Like removeAttribute() but
+        returns a reference to old Attr.
+        (WebCore):
+        * dom/ElementAttributeData.h:
+        (ElementAttributeData):
+        * dom/NamedNodeMap.cpp:
+        (WebCore::NamedNodeMap::removeNamedItem): Avoid looking up the property twice by
+        getting the index directly from the name, instead of going through the qualified name.
+        * dom/NamedNodeMap.h: Remove now unused internal methods for removing attributes.
+
 2012-03-07  Alexey Proskuryakov  <a...@apple.com>
 
         Merge AsyncFileStream with FileStreamProxy

Modified: trunk/Source/WebCore/dom/Element.cpp (110085 => 110086)


--- trunk/Source/WebCore/dom/Element.cpp	2012-03-07 20:23:37 UTC (rev 110085)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-03-07 20:37:32 UTC (rev 110086)
@@ -186,10 +186,9 @@
 
 void Element::removeAttribute(const QualifiedName& name)
 {
-    if (!m_attributeMap)
+    if (!attributeData())
         return;
-
-    m_attributeMap->removeAttribute(name);
+    attributeData()->removeAttribute(name, this);
 }
 
 void Element::setBooleanAttribute(const QualifiedName& name, bool value)
@@ -1417,11 +1416,17 @@
 
     ASSERT(document() == attr->document());
 
-    NamedNodeMap* attrs = updatedAttributes();
-    if (!attrs)
+    ElementAttributeData* attributeData = updatedAttributeData();
+    if (!attributeData)
         return 0;
 
-    return static_pointer_cast<Attr>(attrs->removeNamedItem(attr->qualifiedName(), ec));
+    size_t index = attributeData->getAttributeItemIndex(attr->qualifiedName());
+    if (index == notFound) {
+        ec = NOT_FOUND_ERR;
+        return 0;
+    }
+
+    return attributeData->takeAttribute(index, this);
 }
 
 void Element::setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode& ec, FragmentScriptingPermission scriptingPermission)

Modified: trunk/Source/WebCore/dom/Element.h (110085 => 110086)


--- trunk/Source/WebCore/dom/Element.h	2012-03-07 20:23:37 UTC (rev 110085)
+++ trunk/Source/WebCore/dom/Element.h	2012-03-07 20:37:32 UTC (rev 110086)
@@ -160,7 +160,6 @@
     size_t attributeCount() const;
     Attribute* attributeItem(unsigned index) const;
     Attribute* getAttributeItem(const QualifiedName&) const;
-    void removeAttribute(unsigned index);
 
     void scrollIntoView(bool alignToTop = true);
     void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
@@ -673,12 +672,6 @@
     return m_attributeMap->attributeData()->getAttributeItem(name);
 }
 
-inline void Element::removeAttribute(unsigned index)
-{
-    ASSERT(m_attributeMap);
-    m_attributeMap->removeAttribute(index);
-}
-
 inline void Element::updateInvalidAttributes() const
 {
     if (!isStyleAttributeValid())

Modified: trunk/Source/WebCore/dom/ElementAttributeData.cpp (110085 => 110086)


--- trunk/Source/WebCore/dom/ElementAttributeData.cpp	2012-03-07 20:23:37 UTC (rev 110085)
+++ trunk/Source/WebCore/dom/ElementAttributeData.cpp	2012-03-07 20:37:32 UTC (rev 110086)
@@ -103,6 +103,16 @@
         element->didRemoveAttribute(attribute.get());
 }
 
+PassRefPtr<Attr> ElementAttributeData::takeAttribute(size_t index, Element* element)
+{
+    ASSERT(index < length());
+    ASSERT(element);
+
+    RefPtr<Attr> attr = m_attributes[index]->createAttrIfNeeded(element);
+    removeAttribute(index, element);
+    return attr.release();
+}
+
 bool ElementAttributeData::isEquivalent(const ElementAttributeData* other) const
 {
     if (!other)

Modified: trunk/Source/WebCore/dom/ElementAttributeData.h (110085 => 110086)


--- trunk/Source/WebCore/dom/ElementAttributeData.h	2012-03-07 20:23:37 UTC (rev 110085)
+++ trunk/Source/WebCore/dom/ElementAttributeData.h	2012-03-07 20:37:32 UTC (rev 110086)
@@ -109,6 +109,7 @@
     void addAttribute(PassRefPtr<Attribute>, Element*);
     void removeAttribute(const QualifiedName&, Element*);
     void removeAttribute(size_t index, Element*);
+    PassRefPtr<Attr> takeAttribute(size_t index, Element*);
 
     bool hasID() const { return !m_idForStyleResolution.isNull(); }
     bool hasClass() const { return !m_classNames.isNull(); }

Modified: trunk/Source/WebCore/dom/NamedNodeMap.cpp (110085 => 110086)


--- trunk/Source/WebCore/dom/NamedNodeMap.cpp	2012-03-07 20:23:37 UTC (rev 110085)
+++ trunk/Source/WebCore/dom/NamedNodeMap.cpp	2012-03-07 20:37:32 UTC (rev 110086)
@@ -68,13 +68,15 @@
 
 PassRefPtr<Node> NamedNodeMap::removeNamedItem(const String& name, ExceptionCode& ec)
 {
-    Attribute* a = m_attributeData.getAttributeItem(name, shouldIgnoreAttributeCase(m_element));
-    if (!a) {
+    ASSERT(m_element);
+
+    size_t index = m_attributeData.getAttributeItemIndex(name, shouldIgnoreAttributeCase(m_element));
+    if (index == notFound) {
         ec = NOT_FOUND_ERR;
         return 0;
     }
     
-    return removeNamedItem(a->name(), ec);
+    return m_attributeData.takeAttribute(index, m_element);
 }
 
 PassRefPtr<Node> NamedNodeMap::removeNamedItemNS(const String& namespaceURI, const String& localName, ExceptionCode& ec)
@@ -122,11 +124,7 @@
         return 0;
     }
 
-    RefPtr<Attr> attr = m_attributeData.m_attributes[index]->createAttrIfNeeded(m_element);
-
-    removeAttribute(index);
-
-    return attr.release();
+    return m_attributeData.takeAttribute(index, m_element);
 }
 
 PassRefPtr<Node> NamedNodeMap::item(unsigned index) const

Modified: trunk/Source/WebCore/dom/NamedNodeMap.h (110085 => 110086)


--- trunk/Source/WebCore/dom/NamedNodeMap.h	2012-03-07 20:23:37 UTC (rev 110085)
+++ trunk/Source/WebCore/dom/NamedNodeMap.h	2012-03-07 20:37:32 UTC (rev 110086)
@@ -65,8 +65,6 @@
 
     // These functions do no error checking.
     void addAttribute(PassRefPtr<Attribute> attribute) { m_attributeData.addAttribute(attribute, m_element); }
-    void removeAttribute(const QualifiedName& name) { m_attributeData.removeAttribute(name, m_element); }
-    void removeAttribute(size_t index) { m_attributeData.removeAttribute(index, m_element); }
 
     Element* element() const { return m_element; }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to