Title: [153959] trunk/Source
Revision
153959
Author
[email protected]
Date
2013-08-12 14:50:06 -0700 (Mon, 12 Aug 2013)

Log Message

Use const AtomicStringImpl* in DocumentOrderedMap
https://bugs.webkit.org/show_bug.cgi?id=119700

Reviewed by Benjamin Poulain.

Use const AtomicStringImpl* in DocumentOrderedMap. It caught at least one bug that HTMLNameCollection'
subclasses' nodeMatches were taking const AtomicString& instead of AtomicStringImpl*. This was forcing
DocumentOrderedMap::getElementByWindowNamedItem and DocumentOrderedMap::getElementByDocumentNamedItem
to create temporary AtomicStrings.

* dom/DocumentOrderedMap.cpp:
(WebCore::keyMatchesId):
(WebCore::keyMatchesName):
(WebCore::keyMatchesMapName):
(WebCore::keyMatchesLowercasedMapName):
(WebCore::keyMatchesLabelForAttribute):
(WebCore::keyMatchesWindowNamedItem):
(WebCore::keyMatchesDocumentNamedItem):
(WebCore::DocumentOrderedMap::add):
(WebCore::DocumentOrderedMap::remove):
(WebCore::DocumentOrderedMap::get):
(WebCore::DocumentOrderedMap::getElementById):
(WebCore::DocumentOrderedMap::getElementByName):
(WebCore::DocumentOrderedMap::getElementByMapName):
(WebCore::DocumentOrderedMap::getElementByLowercasedMapName):
(WebCore::DocumentOrderedMap::getElementByLabelForAttribute):
(WebCore::DocumentOrderedMap::getElementByWindowNamedItem):
(WebCore::DocumentOrderedMap::getElementByDocumentNamedItem):
(WebCore::DocumentOrderedMap::getAllElementsById):
* dom/DocumentOrderedMap.h:
(WebCore::DocumentOrderedMap::containsSingle):
(WebCore::DocumentOrderedMap::contains):
(WebCore::DocumentOrderedMap::containsMultiple):
* html/HTMLNameCollection.cpp:
(WebCore::WindowNameCollection::nodeMatches):
(WebCore::DocumentNameCollection::nodeMatches):
* html/HTMLNameCollection.h:
(WebCore::WindowNameCollection::nodeMatches):
(WebCore::DocumentNameCollection::nodeMatches):

Modified Paths

Diff

Modified: trunk/Source/WTF/wtf/text/AtomicStringImpl.h (153958 => 153959)


--- trunk/Source/WTF/wtf/text/AtomicStringImpl.h	2013-08-12 21:37:06 UTC (rev 153958)
+++ trunk/Source/WTF/wtf/text/AtomicStringImpl.h	2013-08-12 21:50:06 UTC (rev 153959)
@@ -41,6 +41,11 @@
 ValueCheck<AtomicStringImpl*> {
     static void checkConsistency(const AtomicStringImpl*) { }
 };
+
+template<> struct
+ValueCheck<const AtomicStringImpl*> {
+    static void checkConsistency(const AtomicStringImpl*) { }
+};
 #endif
 
 }

Modified: trunk/Source/WebCore/ChangeLog (153958 => 153959)


--- trunk/Source/WebCore/ChangeLog	2013-08-12 21:37:06 UTC (rev 153958)
+++ trunk/Source/WebCore/ChangeLog	2013-08-12 21:50:06 UTC (rev 153959)
@@ -1,3 +1,45 @@
+2013-08-12  Ryosuke Niwa  <[email protected]>
+
+        Use const AtomicStringImpl* in DocumentOrderedMap
+        https://bugs.webkit.org/show_bug.cgi?id=119700
+
+        Reviewed by Benjamin Poulain.
+
+        Use const AtomicStringImpl* in DocumentOrderedMap. It caught at least one bug that HTMLNameCollection'
+        subclasses' nodeMatches were taking const AtomicString& instead of AtomicStringImpl*. This was forcing
+        DocumentOrderedMap::getElementByWindowNamedItem and DocumentOrderedMap::getElementByDocumentNamedItem
+        to create temporary AtomicStrings.
+
+        * dom/DocumentOrderedMap.cpp:
+        (WebCore::keyMatchesId):
+        (WebCore::keyMatchesName):
+        (WebCore::keyMatchesMapName):
+        (WebCore::keyMatchesLowercasedMapName):
+        (WebCore::keyMatchesLabelForAttribute):
+        (WebCore::keyMatchesWindowNamedItem):
+        (WebCore::keyMatchesDocumentNamedItem):
+        (WebCore::DocumentOrderedMap::add):
+        (WebCore::DocumentOrderedMap::remove):
+        (WebCore::DocumentOrderedMap::get):
+        (WebCore::DocumentOrderedMap::getElementById):
+        (WebCore::DocumentOrderedMap::getElementByName):
+        (WebCore::DocumentOrderedMap::getElementByMapName):
+        (WebCore::DocumentOrderedMap::getElementByLowercasedMapName):
+        (WebCore::DocumentOrderedMap::getElementByLabelForAttribute):
+        (WebCore::DocumentOrderedMap::getElementByWindowNamedItem):
+        (WebCore::DocumentOrderedMap::getElementByDocumentNamedItem):
+        (WebCore::DocumentOrderedMap::getAllElementsById):
+        * dom/DocumentOrderedMap.h:
+        (WebCore::DocumentOrderedMap::containsSingle):
+        (WebCore::DocumentOrderedMap::contains):
+        (WebCore::DocumentOrderedMap::containsMultiple):
+        * html/HTMLNameCollection.cpp:
+        (WebCore::WindowNameCollection::nodeMatches):
+        (WebCore::DocumentNameCollection::nodeMatches):
+        * html/HTMLNameCollection.h:
+        (WebCore::WindowNameCollection::nodeMatches):
+        (WebCore::DocumentNameCollection::nodeMatches):
+
 2013-08-12  Beth Dakin  <[email protected]>
 
         The LayoutMilestones didLayout callback should only fire for the main frame

Modified: trunk/Source/WebCore/dom/DocumentOrderedMap.cpp (153958 => 153959)


--- trunk/Source/WebCore/dom/DocumentOrderedMap.cpp	2013-08-12 21:37:06 UTC (rev 153958)
+++ trunk/Source/WebCore/dom/DocumentOrderedMap.cpp	2013-08-12 21:50:06 UTC (rev 153959)
@@ -43,37 +43,37 @@
 
 using namespace HTMLNames;
 
-inline bool keyMatchesId(AtomicStringImpl* key, Element* element)
+inline bool keyMatchesId(const AtomicStringImpl* key, Element* element)
 {
     return element->getIdAttribute().impl() == key;
 }
 
-inline bool keyMatchesName(AtomicStringImpl* key, Element* element)
+inline bool keyMatchesName(const AtomicStringImpl* key, Element* element)
 {
     return element->getNameAttribute().impl() == key;
 }
 
-inline bool keyMatchesMapName(AtomicStringImpl* key, Element* element)
+inline bool keyMatchesMapName(const AtomicStringImpl* key, Element* element)
 {
     return isHTMLMapElement(element) && toHTMLMapElement(element)->getName().impl() == key;
 }
 
-inline bool keyMatchesLowercasedMapName(AtomicStringImpl* key, Element* element)
+inline bool keyMatchesLowercasedMapName(const AtomicStringImpl* key, Element* element)
 {
     return isHTMLMapElement(element) && toHTMLMapElement(element)->getName().lower().impl() == key;
 }
 
-inline bool keyMatchesLabelForAttribute(AtomicStringImpl* key, Element* element)
+inline bool keyMatchesLabelForAttribute(const AtomicStringImpl* key, Element* element)
 {
     return isHTMLLabelElement(element) && element->getAttribute(forAttr).impl() == key;
 }
 
-inline bool keyMatchesWindowNamedItem(AtomicStringImpl* key, Element* element)
+inline bool keyMatchesWindowNamedItem(const AtomicStringImpl* key, Element* element)
 {
     return WindowNameCollection::nodeMatches(element, key);
 }
 
-inline bool keyMatchesDocumentNamedItem(AtomicStringImpl* key, Element* element)
+inline bool keyMatchesDocumentNamedItem(const AtomicStringImpl* key, Element* element)
 {
     return DocumentNameCollection::nodeMatches(element, key);
 }
@@ -83,7 +83,7 @@
     m_map.clear();
 }
 
-void DocumentOrderedMap::add(AtomicStringImpl* key, Element* element)
+void DocumentOrderedMap::add(const AtomicStringImpl* key, Element* element)
 {
     ASSERT(key);
     ASSERT(element);
@@ -99,7 +99,7 @@
     entry.orderedList.clear();
 }
 
-void DocumentOrderedMap::remove(AtomicStringImpl* key, Element* element)
+void DocumentOrderedMap::remove(const AtomicStringImpl* key, Element* element)
 {
     ASSERT(key);
     ASSERT(element);
@@ -121,8 +121,8 @@
     }
 }
 
-template<bool keyMatches(AtomicStringImpl*, Element*)>
-inline Element* DocumentOrderedMap::get(AtomicStringImpl* key, const TreeScope* scope) const
+template<bool keyMatches(const AtomicStringImpl*, Element*)>
+inline Element* DocumentOrderedMap::get(const AtomicStringImpl* key, const TreeScope* scope) const
 {
     ASSERT(key);
     ASSERT(scope);
@@ -149,42 +149,42 @@
     return 0;
 }
 
-Element* DocumentOrderedMap::getElementById(AtomicStringImpl* key, const TreeScope* scope) const
+Element* DocumentOrderedMap::getElementById(const AtomicStringImpl* key, const TreeScope* scope) const
 {
     return get<keyMatchesId>(key, scope);
 }
 
-Element* DocumentOrderedMap::getElementByName(AtomicStringImpl* key, const TreeScope* scope) const
+Element* DocumentOrderedMap::getElementByName(const AtomicStringImpl* key, const TreeScope* scope) const
 {
     return get<keyMatchesName>(key, scope);
 }
 
-Element* DocumentOrderedMap::getElementByMapName(AtomicStringImpl* key, const TreeScope* scope) const
+Element* DocumentOrderedMap::getElementByMapName(const AtomicStringImpl* key, const TreeScope* scope) const
 {
     return get<keyMatchesMapName>(key, scope);
 }
 
-Element* DocumentOrderedMap::getElementByLowercasedMapName(AtomicStringImpl* key, const TreeScope* scope) const
+Element* DocumentOrderedMap::getElementByLowercasedMapName(const AtomicStringImpl* key, const TreeScope* scope) const
 {
     return get<keyMatchesLowercasedMapName>(key, scope);
 }
 
-Element* DocumentOrderedMap::getElementByLabelForAttribute(AtomicStringImpl* key, const TreeScope* scope) const
+Element* DocumentOrderedMap::getElementByLabelForAttribute(const AtomicStringImpl* key, const TreeScope* scope) const
 {
     return get<keyMatchesLabelForAttribute>(key, scope);
 }
 
-Element* DocumentOrderedMap::getElementByWindowNamedItem(AtomicStringImpl* key, const TreeScope* scope) const
+Element* DocumentOrderedMap::getElementByWindowNamedItem(const AtomicStringImpl* key, const TreeScope* scope) const
 {
     return get<keyMatchesWindowNamedItem>(key, scope);
 }
 
-Element* DocumentOrderedMap::getElementByDocumentNamedItem(AtomicStringImpl* key, const TreeScope* scope) const
+Element* DocumentOrderedMap::getElementByDocumentNamedItem(const AtomicStringImpl* key, const TreeScope* scope) const
 {
     return get<keyMatchesDocumentNamedItem>(key, scope);
 }
 
-const Vector<Element*>* DocumentOrderedMap::getAllElementsById(AtomicStringImpl* key, const TreeScope* scope) const
+const Vector<Element*>* DocumentOrderedMap::getAllElementsById(const AtomicStringImpl* key, const TreeScope* scope) const
 {
     ASSERT(key);
     ASSERT(scope);

Modified: trunk/Source/WebCore/dom/DocumentOrderedMap.h (153958 => 153959)


--- trunk/Source/WebCore/dom/DocumentOrderedMap.h	2013-08-12 21:37:06 UTC (rev 153958)
+++ trunk/Source/WebCore/dom/DocumentOrderedMap.h	2013-08-12 21:50:06 UTC (rev 153959)
@@ -43,29 +43,29 @@
 
 class DocumentOrderedMap {
 public:
-    void add(AtomicStringImpl*, Element*);
-    void remove(AtomicStringImpl*, Element*);
+    void add(const AtomicStringImpl*, Element*);
+    void remove(const AtomicStringImpl*, Element*);
     void clear();
 
-    bool contains(AtomicStringImpl*) const;
-    bool containsSingle(AtomicStringImpl*) const;
-    bool containsMultiple(AtomicStringImpl*) const;
+    bool contains(const AtomicStringImpl*) const;
+    bool containsSingle(const AtomicStringImpl*) const;
+    bool containsMultiple(const AtomicStringImpl*) const;
 
     // concrete instantiations of the get<>() method template
-    Element* getElementById(AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByName(AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByMapName(AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByLowercasedMapName(AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByLabelForAttribute(AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByWindowNamedItem(AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByDocumentNamedItem(AtomicStringImpl*, const TreeScope*) const;
+    Element* getElementById(const AtomicStringImpl*, const TreeScope*) const;
+    Element* getElementByName(const AtomicStringImpl*, const TreeScope*) const;
+    Element* getElementByMapName(const AtomicStringImpl*, const TreeScope*) const;
+    Element* getElementByLowercasedMapName(const AtomicStringImpl*, const TreeScope*) const;
+    Element* getElementByLabelForAttribute(const AtomicStringImpl*, const TreeScope*) const;
+    Element* getElementByWindowNamedItem(const AtomicStringImpl*, const TreeScope*) const;
+    Element* getElementByDocumentNamedItem(const AtomicStringImpl*, const TreeScope*) const;
 
-    const Vector<Element*>* getAllElementsById(AtomicStringImpl*, const TreeScope*) const;
+    const Vector<Element*>* getAllElementsById(const AtomicStringImpl*, const TreeScope*) const;
 
     void checkConsistency() const;
 
 private:
-    template<bool keyMatches(AtomicStringImpl*, Element*)> Element* get(AtomicStringImpl*, const TreeScope*) const;
+    template<bool keyMatches(const AtomicStringImpl*, Element*)> Element* get(const AtomicStringImpl*, const TreeScope*) const;
 
     struct MapEntry {
         MapEntry()
@@ -82,23 +82,23 @@
         Vector<Element*> orderedList;
     };
 
-    typedef HashMap<AtomicStringImpl*, MapEntry> Map;
+    typedef HashMap<const AtomicStringImpl*, MapEntry> Map;
 
     mutable Map m_map;
 };
 
-inline bool DocumentOrderedMap::containsSingle(AtomicStringImpl* id) const
+inline bool DocumentOrderedMap::containsSingle(const AtomicStringImpl* id) const
 {
     Map::const_iterator it = m_map.find(id);
     return it != m_map.end() && it->value.count == 1;
 }
 
-inline bool DocumentOrderedMap::contains(AtomicStringImpl* id) const
+inline bool DocumentOrderedMap::contains(const AtomicStringImpl* id) const
 {
     return m_map.contains(id);
 }
 
-inline bool DocumentOrderedMap::containsMultiple(AtomicStringImpl* id) const
+inline bool DocumentOrderedMap::containsMultiple(const AtomicStringImpl* id) const
 {
     Map::const_iterator it = m_map.find(id);
     return it != m_map.end() && it->value.count > 1;

Modified: trunk/Source/WebCore/html/HTMLNameCollection.cpp (153958 => 153959)


--- trunk/Source/WebCore/html/HTMLNameCollection.cpp	2013-08-12 21:37:06 UTC (rev 153958)
+++ trunk/Source/WebCore/html/HTMLNameCollection.cpp	2013-08-12 21:50:06 UTC (rev 153959)
@@ -57,12 +57,12 @@
         || element->hasTagName(embedTag) || element->hasTagName(objectTag);
 }
 
-bool WindowNameCollection::nodeMatches(Element* element, const AtomicString& name)
+bool WindowNameCollection::nodeMatches(Element* element, const AtomicStringImpl* name)
 {
     // Find only images, forms, applets, embeds and objects by name, but anything by id
-    if (nodeMatchesIfNameAttributeMatch(element) && element->getNameAttribute() == name)
+    if (nodeMatchesIfNameAttributeMatch(element) && element->getNameAttribute().impl() == name)
         return true;
-    return element->getIdAttribute() == name;
+    return element->getIdAttribute().impl() == name;
 }
 
 bool DocumentNameCollection::nodeMatchesIfIdAttributeMatch(Element* element)
@@ -79,18 +79,18 @@
         || isHTMLImageElement(element);
 }
 
-bool DocumentNameCollection::nodeMatches(Element* element, const AtomicString& name)
+bool DocumentNameCollection::nodeMatches(Element* element, const AtomicStringImpl* name)
 {
     // Find images, forms, applets, embeds, objects and iframes by name, applets and object by id, and images by id
     // but only if they have a name attribute (this very strange rule matches IE)
     if (isHTMLFormElement(element) || element->hasTagName(embedTag) || element->hasTagName(iframeTag))
-        return element->getNameAttribute() == name;
+        return element->getNameAttribute().impl() == name;
     if (element->hasTagName(appletTag))
-        return element->getNameAttribute() == name || element->getIdAttribute() == name;
+        return element->getNameAttribute().impl() == name || element->getIdAttribute().impl() == name;
     if (element->hasTagName(objectTag))
-        return (element->getNameAttribute() == name || element->getIdAttribute() == name) && toHTMLObjectElement(element)->isDocNamedItem();
+        return (element->getNameAttribute().impl() == name || element->getIdAttribute().impl() == name) && toHTMLObjectElement(element)->isDocNamedItem();
     if (isHTMLImageElement(element))
-        return element->getNameAttribute() == name || (element->getIdAttribute() == name && element->hasName());
+        return element->getNameAttribute().impl() == name || (element->getIdAttribute().impl() == name && element->hasName());
     return false;
 }
 

Modified: trunk/Source/WebCore/html/HTMLNameCollection.h (153958 => 153959)


--- trunk/Source/WebCore/html/HTMLNameCollection.h	2013-08-12 21:37:06 UTC (rev 153958)
+++ trunk/Source/WebCore/html/HTMLNameCollection.h	2013-08-12 21:50:06 UTC (rev 153959)
@@ -48,11 +48,11 @@
         return adoptRef(new WindowNameCollection(document, type, name));
     }
 
-    bool nodeMatches(Element* element) const { return nodeMatches(element, m_name); }
+    bool nodeMatches(Element* element) const { return nodeMatches(element, m_name.impl()); }
 
     static bool nodeMatchesIfIdAttributeMatch(Element*) { return true; }
     static bool nodeMatchesIfNameAttributeMatch(Element*);
-    static bool nodeMatches(Element*, const AtomicString&);
+    static bool nodeMatches(Element*, const AtomicStringImpl*);
 
 private:
     WindowNameCollection(Node* document, CollectionType type, const AtomicString& name)
@@ -71,9 +71,9 @@
 
     static bool nodeMatchesIfIdAttributeMatch(Element*);
     static bool nodeMatchesIfNameAttributeMatch(Element*);
-    bool nodeMatches(Element* element) const { return nodeMatches(element, m_name); }
+    bool nodeMatches(Element* element) const { return nodeMatches(element, m_name.impl()); }
 
-    static bool nodeMatches(Element*, const AtomicString&);
+    static bool nodeMatches(Element*, const AtomicStringImpl*);
 
 private:
     DocumentNameCollection(Node* document, CollectionType type, const AtomicString& name)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to