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()