Title: [109585] trunk/Source/WebCore
Revision
109585
Author
caio.olive...@openbossa.org
Date
2012-03-02 11:02:04 -0800 (Fri, 02 Mar 2012)

Log Message

Create a method in Element to compare attributes with other Element
https://bugs.webkit.org/show_bug.cgi?id=80169

Reviewed by Ryosuke Niwa.

Avoid manually peeking at attribute storage to get this information. This
simplify the callsites. The actual implementation of comparison was moved to
ElementAttributeData. The mapsEquivalent() function still exists for the sake
of DocumentType nodes.

* dom/Element.cpp:
(WebCore::Element::hasEquivalentAttributes):
(WebCore):
* dom/Element.h:
(Element):
* dom/ElementAttributeData.cpp:
(WebCore::ElementAttributeData::isEquivalent):
(WebCore):
* dom/ElementAttributeData.h:
(ElementAttributeData):
* dom/NamedNodeMap.cpp:
(WebCore::NamedNodeMap::mapsEquivalent):
* dom/Node.cpp:
(WebCore::Node::isEqualNode):
* editing/htmlediting.cpp:
(WebCore::areIdenticalElements): Use Element::hasTagName() instead of matching
directly to make code a bit clearer.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (109584 => 109585)


--- trunk/Source/WebCore/ChangeLog	2012-03-02 18:03:59 UTC (rev 109584)
+++ trunk/Source/WebCore/ChangeLog	2012-03-02 19:02:04 UTC (rev 109585)
@@ -1,3 +1,33 @@
+2012-03-02  Caio Marcelo de Oliveira Filho  <caio.olive...@openbossa.org>
+
+        Create a method in Element to compare attributes with other Element
+        https://bugs.webkit.org/show_bug.cgi?id=80169
+
+        Reviewed by Ryosuke Niwa.
+
+        Avoid manually peeking at attribute storage to get this information. This
+        simplify the callsites. The actual implementation of comparison was moved to
+        ElementAttributeData. The mapsEquivalent() function still exists for the sake
+        of DocumentType nodes.
+
+        * dom/Element.cpp:
+        (WebCore::Element::hasEquivalentAttributes):
+        (WebCore):
+        * dom/Element.h:
+        (Element):
+        * dom/ElementAttributeData.cpp:
+        (WebCore::ElementAttributeData::isEquivalent):
+        (WebCore):
+        * dom/ElementAttributeData.h:
+        (ElementAttributeData):
+        * dom/NamedNodeMap.cpp:
+        (WebCore::NamedNodeMap::mapsEquivalent):
+        * dom/Node.cpp:
+        (WebCore::Node::isEqualNode):
+        * editing/htmlediting.cpp:
+        (WebCore::areIdenticalElements): Use Element::hasTagName() instead of matching
+        directly to make code a bit clearer.
+
 2012-03-02  Zan Dobersek  <zandober...@gmail.com>
 
         [GTK] Smooth scrolling support

Modified: trunk/Source/WebCore/dom/Element.cpp (109584 => 109585)


--- trunk/Source/WebCore/dom/Element.cpp	2012-03-02 18:03:59 UTC (rev 109584)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-03-02 19:02:04 UTC (rev 109585)
@@ -775,6 +775,17 @@
     return m_attributeMap && m_attributeMap->length();
 }
 
+bool Element::hasEquivalentAttributes(const Element* other) const
+{
+    ElementAttributeData* attributeData = updatedAttributeData();
+    ElementAttributeData* otherAttributeData = other->updatedAttributeData();
+    if (attributeData)
+        return attributeData->isEquivalent(otherAttributeData);
+    if (otherAttributeData)
+        return otherAttributeData->isEquivalent(attributeData);
+    return true;
+}
+
 String Element::nodeName() const
 {
     return m_tagName.toString();

Modified: trunk/Source/WebCore/dom/Element.h (109584 => 109585)


--- trunk/Source/WebCore/dom/Element.h	2012-03-02 18:03:59 UTC (rev 109584)
+++ trunk/Source/WebCore/dom/Element.h	2012-03-02 19:02:04 UTC (rev 109585)
@@ -245,6 +245,7 @@
     ElementAttributeData* ensureUpdatedAttributeData() const;
 
     void setAttributesFromElement(const Element&);
+    bool hasEquivalentAttributes(const Element* other) const;
 
     virtual void copyNonAttributeProperties(const Element* source);
 

Modified: trunk/Source/WebCore/dom/ElementAttributeData.cpp (109584 => 109585)


--- trunk/Source/WebCore/dom/ElementAttributeData.cpp	2012-03-02 18:03:59 UTC (rev 109584)
+++ trunk/Source/WebCore/dom/ElementAttributeData.cpp	2012-03-02 19:02:04 UTC (rev 109585)
@@ -103,6 +103,25 @@
         element->didRemoveAttribute(attribute.get());
 }
 
+bool ElementAttributeData::isEquivalent(const ElementAttributeData* other) const
+{
+    if (!other)
+        return isEmpty();
+
+    unsigned len = length();
+    if (len != other->length())
+        return false;
+
+    for (unsigned i = 0; i < len; i++) {
+        Attribute* attr = attributeItem(i);
+        Attribute* otherAttr = other->getAttributeItem(attr->name());
+        if (!otherAttr || attr->value() != otherAttr->value())
+            return false;
+    }
+
+    return true;
+}
+
 void ElementAttributeData::detachAttributesFromElement()
 {
     size_t size = m_attributes.size();

Modified: trunk/Source/WebCore/dom/ElementAttributeData.h (109584 => 109585)


--- trunk/Source/WebCore/dom/ElementAttributeData.h	2012-03-02 18:03:59 UTC (rev 109584)
+++ trunk/Source/WebCore/dom/ElementAttributeData.h	2012-03-02 19:02:04 UTC (rev 109585)
@@ -113,6 +113,8 @@
     bool hasID() const { return !m_idForStyleResolution.isNull(); }
     bool hasClass() const { return !m_classNames.isNull(); }
 
+    bool isEquivalent(const ElementAttributeData* other) const;
+
 private:
     friend class Element;
     friend class NamedNodeMap;

Modified: trunk/Source/WebCore/dom/NamedNodeMap.cpp (109584 => 109585)


--- trunk/Source/WebCore/dom/NamedNodeMap.cpp	2012-03-02 18:03:59 UTC (rev 109584)
+++ trunk/Source/WebCore/dom/NamedNodeMap.cpp	2012-03-02 19:02:04 UTC (rev 109585)
@@ -172,20 +172,7 @@
 {
     if (!otherMap)
         return m_attributeData.isEmpty();
-    
-    unsigned len = length();
-    if (len != otherMap->length())
-        return false;
-    
-    const ElementAttributeData& otherAttributeData = otherMap->m_attributeData;
-    for (unsigned i = 0; i < len; i++) {
-        Attribute* attr = m_attributeData.attributeItem(i);
-        Attribute* otherAttr = otherAttributeData.getAttributeItem(attr->name());
-        if (!otherAttr || attr->value() != otherAttr->value())
-            return false;
-    }
-    
-    return true;
+    return m_attributeData.isEquivalent(otherMap->attributeData());
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/Node.cpp (109584 => 109585)


--- trunk/Source/WebCore/dom/Node.cpp	2012-03-02 18:03:59 UTC (rev 109584)
+++ trunk/Source/WebCore/dom/Node.cpp	2012-03-02 19:02:04 UTC (rev 109585)
@@ -1772,18 +1772,8 @@
     if (nodeValue() != other->nodeValue())
         return false;
     
-    if (isElementNode()) {
-        NamedNodeMap* attributes = toElement(this)->updatedAttributes();
-        NamedNodeMap* otherAttributes = toElement(other)->updatedAttributes();
-
-        if (attributes) {
-            if (!attributes->mapsEquivalent(otherAttributes))
-                return false;
-        } else if (otherAttributes) {
-            if (!otherAttributes->mapsEquivalent(attributes))
-                return false;
-        }
-    }
+    if (isElementNode() && !toElement(this)->hasEquivalentAttributes(toElement(other)))
+        return false;
     
     Node* child = firstChild();
     Node* otherChild = other->firstChild();

Modified: trunk/Source/WebCore/editing/htmlediting.cpp (109584 => 109585)


--- trunk/Source/WebCore/editing/htmlediting.cpp	2012-03-02 18:03:59 UTC (rev 109584)
+++ trunk/Source/WebCore/editing/htmlediting.cpp	2012-03-02 19:02:04 UTC (rev 109585)
@@ -1153,22 +1153,15 @@
 
 bool areIdenticalElements(const Node* first, const Node* second)
 {
-    // check that tag name and all attribute names and values are identical
-
     if (!first->isElementNode() || !second->isElementNode())
         return false;
 
-    if (!toElement(first)->tagQName().matches(toElement(second)->tagQName()))
+    const Element* firstElement = toElement(first);
+    const Element* secondElement = toElement(second);
+    if (!firstElement->hasTagName(secondElement->tagQName()))
         return false;
 
-    NamedNodeMap* firstMap = toElement(first)->updatedAttributes();
-    NamedNodeMap* secondMap = toElement(second)->updatedAttributes();
-
-    if (firstMap)
-        return firstMap->mapsEquivalent(secondMap);
-    if (secondMap)
-        return secondMap->mapsEquivalent(firstMap);
-    return true;
+    return firstElement->hasEquivalentAttributes(secondElement);
 }
 
 bool isNonTableCellHTMLBlockElement(const Node* node)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to