Title: [175697] trunk/Source/WebCore
Revision
175697
Author
cdu...@apple.com
Date
2014-11-06 08:00:24 -0800 (Thu, 06 Nov 2014)

Log Message

Use lambda functions in DocumentOrderedMap
https://bugs.webkit.org/show_bug.cgi?id=138376

Reviewed by Darin Adler.

Use lambda functions in DocumentOrderedMap instead of separate named
functions.

No new tests, no behavior change.

* dom/DocumentOrderedMap.cpp:
(WebCore::DocumentOrderedMap::get):
(WebCore::DocumentOrderedMap::getElementById):
(WebCore::DocumentOrderedMap::getElementByName):
(WebCore::DocumentOrderedMap::getElementByMapName):
(WebCore::DocumentOrderedMap::getElementByLowercasedMapName):
(WebCore::DocumentOrderedMap::getElementByLowercasedUsemap):
(WebCore::DocumentOrderedMap::getElementByLabelForAttribute):
(WebCore::DocumentOrderedMap::getElementByWindowNamedItem):
(WebCore::DocumentOrderedMap::getElementByDocumentNamedItem):
(WebCore::DocumentOrderedMap::getAllElementsById):
(WebCore::keyMatchesId): Deleted.
(WebCore::keyMatchesName): Deleted.
(WebCore::keyMatchesMapName): Deleted.
(WebCore::keyMatchesLowercasedMapName): Deleted.
(WebCore::keyMatchesLowercasedUsemap): Deleted.
(WebCore::keyMatchesLabelForAttribute): Deleted.
(WebCore::keyMatchesWindowNamedItem): Deleted.
(WebCore::keyMatchesDocumentNamedItem): Deleted.
* dom/DocumentOrderedMap.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (175696 => 175697)


--- trunk/Source/WebCore/ChangeLog	2014-11-06 15:46:34 UTC (rev 175696)
+++ trunk/Source/WebCore/ChangeLog	2014-11-06 16:00:24 UTC (rev 175697)
@@ -1,3 +1,36 @@
+2014-11-06  Chris Dumez  <cdu...@apple.com>
+
+        Use lambda functions in DocumentOrderedMap
+        https://bugs.webkit.org/show_bug.cgi?id=138376
+
+        Reviewed by Darin Adler.
+
+        Use lambda functions in DocumentOrderedMap instead of separate named
+        functions.
+
+        No new tests, no behavior change.
+
+        * dom/DocumentOrderedMap.cpp:
+        (WebCore::DocumentOrderedMap::get):
+        (WebCore::DocumentOrderedMap::getElementById):
+        (WebCore::DocumentOrderedMap::getElementByName):
+        (WebCore::DocumentOrderedMap::getElementByMapName):
+        (WebCore::DocumentOrderedMap::getElementByLowercasedMapName):
+        (WebCore::DocumentOrderedMap::getElementByLowercasedUsemap):
+        (WebCore::DocumentOrderedMap::getElementByLabelForAttribute):
+        (WebCore::DocumentOrderedMap::getElementByWindowNamedItem):
+        (WebCore::DocumentOrderedMap::getElementByDocumentNamedItem):
+        (WebCore::DocumentOrderedMap::getAllElementsById):
+        (WebCore::keyMatchesId): Deleted.
+        (WebCore::keyMatchesName): Deleted.
+        (WebCore::keyMatchesMapName): Deleted.
+        (WebCore::keyMatchesLowercasedMapName): Deleted.
+        (WebCore::keyMatchesLowercasedUsemap): Deleted.
+        (WebCore::keyMatchesLabelForAttribute): Deleted.
+        (WebCore::keyMatchesWindowNamedItem): Deleted.
+        (WebCore::keyMatchesDocumentNamedItem): Deleted.
+        * dom/DocumentOrderedMap.h:
+
 2014-11-05  Shivakumar JM  <shiva...@samsung.com>
 
         splitText API does not match DOM specification.

Modified: trunk/Source/WebCore/dom/DocumentOrderedMap.cpp (175696 => 175697)


--- trunk/Source/WebCore/dom/DocumentOrderedMap.cpp	2014-11-06 15:46:34 UTC (rev 175696)
+++ trunk/Source/WebCore/dom/DocumentOrderedMap.cpp	2014-11-06 16:00:24 UTC (rev 175697)
@@ -41,47 +41,6 @@
 
 using namespace HTMLNames;
 
-inline bool keyMatchesId(const AtomicStringImpl& key, const Element& element)
-{
-    return element.getIdAttribute().impl() == &key;
-}
-
-inline bool keyMatchesName(const AtomicStringImpl& key, const Element& element)
-{
-    return element.getNameAttribute().impl() == &key;
-}
-
-inline bool keyMatchesMapName(const AtomicStringImpl& key, const Element& element)
-{
-    return is<HTMLMapElement>(element) && downcast<HTMLMapElement>(element).getName().impl() == &key;
-}
-
-inline bool keyMatchesLowercasedMapName(const AtomicStringImpl& key, const Element& element)
-{
-    return is<HTMLMapElement>(element) && downcast<HTMLMapElement>(element).getName().lower().impl() == &key;
-}
-
-inline bool keyMatchesLowercasedUsemap(const AtomicStringImpl& key, const Element& element)
-{
-    // FIXME: HTML5 specification says we should match both image and object elements.
-    return is<HTMLImageElement>(element) && downcast<HTMLImageElement>(element).matchesLowercasedUsemap(key);
-}
-
-inline bool keyMatchesLabelForAttribute(const AtomicStringImpl& key, const Element& element)
-{
-    return is<HTMLLabelElement>(element) && element.fastGetAttribute(forAttr).impl() == &key;
-}
-
-inline bool keyMatchesWindowNamedItem(const AtomicStringImpl& key, const Element& element)
-{
-    return WindowNameCollection::elementMatches(element, &key);
-}
-
-inline bool keyMatchesDocumentNamedItem(const AtomicStringImpl& key, const Element& element)
-{
-    return DocumentNameCollection::elementMatches(element, &key);
-}
-
 void DocumentOrderedMap::clear()
 {
     m_map.clear();
@@ -126,8 +85,8 @@
     }
 }
 
-template<bool keyMatches(const AtomicStringImpl&, const Element&)>
-inline Element* DocumentOrderedMap::get(const AtomicStringImpl& key, const TreeScope& scope) const
+template <typename KeyMatchingFunction>
+inline Element* DocumentOrderedMap::get(const AtomicStringImpl& key, const TreeScope& scope, const KeyMatchingFunction& keyMatches) const
 {
     m_map.checkConsistency();
 
@@ -158,42 +117,59 @@
 
 Element* DocumentOrderedMap::getElementById(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return get<keyMatchesId>(key, scope);
+    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return element.getIdAttribute().impl() == &key;
+    });
 }
 
 Element* DocumentOrderedMap::getElementByName(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return get<keyMatchesName>(key, scope);
+    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return element.getNameAttribute().impl() == &key;
+    });
 }
 
 HTMLMapElement* DocumentOrderedMap::getElementByMapName(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return downcast<HTMLMapElement>(get<keyMatchesMapName>(key, scope));
+    return downcast<HTMLMapElement>(get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return is<HTMLMapElement>(element) && downcast<HTMLMapElement>(element).getName().impl() == &key;
+    }));
 }
 
 HTMLMapElement* DocumentOrderedMap::getElementByLowercasedMapName(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return downcast<HTMLMapElement>(get<keyMatchesLowercasedMapName>(key, scope));
+    return downcast<HTMLMapElement>(get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return is<HTMLMapElement>(element) && downcast<HTMLMapElement>(element).getName().lower().impl() == &key;
+    }));
 }
 
 HTMLImageElement* DocumentOrderedMap::getElementByLowercasedUsemap(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return downcast<HTMLImageElement>(get<keyMatchesLowercasedUsemap>(key, scope));
+    return downcast<HTMLImageElement>(get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        // FIXME: HTML5 specification says we should match both image and object elements.
+        return is<HTMLImageElement>(element) && downcast<HTMLImageElement>(element).matchesLowercasedUsemap(key);
+    }));
 }
 
 HTMLLabelElement* DocumentOrderedMap::getElementByLabelForAttribute(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return downcast<HTMLLabelElement>(get<keyMatchesLabelForAttribute>(key, scope));
+    return downcast<HTMLLabelElement>(get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return is<HTMLLabelElement>(element) && element.fastGetAttribute(forAttr).impl() == &key;
+    }));
 }
 
 Element* DocumentOrderedMap::getElementByWindowNamedItem(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return get<keyMatchesWindowNamedItem>(key, scope);
+    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return WindowNameCollection::elementMatches(element, &key);
+    });
 }
 
 Element* DocumentOrderedMap::getElementByDocumentNamedItem(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return get<keyMatchesDocumentNamedItem>(key, scope);
+    return get(key, scope, [] (const AtomicStringImpl& key, const Element& element) {
+        return DocumentNameCollection::elementMatches(element, &key);
+    });
 }
 
 const Vector<Element*>* DocumentOrderedMap::getAllElementsById(const AtomicStringImpl& key, const TreeScope& scope) const
@@ -216,7 +192,7 @@
         auto end = elementDescandents.end();
         for (; it != end; ++it) {
             auto& element = *it;
-            if (!keyMatchesId(key, element))
+            if (element.getIdAttribute().impl() != &key)
                 continue;
             entry.orderedList.append(&element);
         }

Modified: trunk/Source/WebCore/dom/DocumentOrderedMap.h (175696 => 175697)


--- trunk/Source/WebCore/dom/DocumentOrderedMap.h	2014-11-06 15:46:34 UTC (rev 175696)
+++ trunk/Source/WebCore/dom/DocumentOrderedMap.h	2014-11-06 16:00:24 UTC (rev 175697)
@@ -68,7 +68,8 @@
     const Vector<Element*>* getAllElementsById(const AtomicStringImpl&, const TreeScope&) const;
 
 private:
-    template<bool keyMatches(const AtomicStringImpl&, const Element&)> Element* get(const AtomicStringImpl&, const TreeScope&) const;
+    template <typename KeyMatchingFunction>
+    Element* get(const AtomicStringImpl&, const TreeScope&, const KeyMatchingFunction&) const;
 
     struct MapEntry {
         MapEntry()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to