Modified: trunk/Source/WebCore/ChangeLog (161571 => 161572)
--- trunk/Source/WebCore/ChangeLog 2014-01-09 20:20:28 UTC (rev 161571)
+++ trunk/Source/WebCore/ChangeLog 2014-01-09 20:22:06 UTC (rev 161572)
@@ -1,3 +1,31 @@
+2014-01-09 Antti Koivisto <[email protected]>
+
+ DocumentOrderedMap should use iterator
+ https://bugs.webkit.org/show_bug.cgi?id=126696
+
+ Reviewed by Andreas Kling.
+
+ * dom/DocumentOrderedMap.cpp:
+ (WebCore::keyMatchesId):
+ (WebCore::keyMatchesName):
+ (WebCore::keyMatchesMapName):
+ (WebCore::keyMatchesLowercasedMapName):
+ (WebCore::keyMatchesLowercasedUsemap):
+ (WebCore::keyMatchesLabelForAttribute):
+ (WebCore::keyMatchesWindowNamedItem):
+ (WebCore::keyMatchesDocumentNamedItem):
+
+ Switch to Element references.
+
+ (WebCore::DocumentOrderedMap::add):
+ (WebCore::DocumentOrderedMap::remove):
+ (WebCore::DocumentOrderedMap::get):
+ (WebCore::DocumentOrderedMap::getAllElementsById):
+
+ Use element iterator instead of ElementTraversal.
+
+ * dom/DocumentOrderedMap.h:
+
2014-01-09 Beth Dakin <[email protected]>
Margin tiles are not repainted when background color changes
Modified: trunk/Source/WebCore/dom/DocumentOrderedMap.cpp (161571 => 161572)
--- trunk/Source/WebCore/dom/DocumentOrderedMap.cpp 2014-01-09 20:20:28 UTC (rev 161571)
+++ trunk/Source/WebCore/dom/DocumentOrderedMap.cpp 2014-01-09 20:22:06 UTC (rev 161572)
@@ -31,7 +31,7 @@
#include "config.h"
#include "DocumentOrderedMap.h"
-#include "ElementTraversal.h"
+#include "ElementIterator.h"
#include "HTMLImageElement.h"
#include "HTMLLabelElement.h"
#include "HTMLMapElement.h"
@@ -41,45 +41,45 @@
using namespace HTMLNames;
-inline bool keyMatchesId(const AtomicStringImpl& key, Element* element)
+inline bool keyMatchesId(const AtomicStringImpl& key, const Element& element)
{
- return element->getIdAttribute().impl() == &key;
+ return element.getIdAttribute().impl() == &key;
}
-inline bool keyMatchesName(const AtomicStringImpl& key, Element* element)
+inline bool keyMatchesName(const AtomicStringImpl& key, const Element& element)
{
- return element->getNameAttribute().impl() == &key;
+ return element.getNameAttribute().impl() == &key;
}
-inline bool keyMatchesMapName(const AtomicStringImpl& key, Element* element)
+inline bool keyMatchesMapName(const AtomicStringImpl& key, const Element& element)
{
- return isHTMLMapElement(element) && toHTMLMapElement(element)->getName().impl() == &key;
+ return isHTMLMapElement(element) && toHTMLMapElement(element).getName().impl() == &key;
}
-inline bool keyMatchesLowercasedMapName(const AtomicStringImpl& key, Element* element)
+inline bool keyMatchesLowercasedMapName(const AtomicStringImpl& key, const Element& element)
{
- return isHTMLMapElement(element) && toHTMLMapElement(element)->getName().lower().impl() == &key;
+ return isHTMLMapElement(element) && toHTMLMapElement(element).getName().lower().impl() == &key;
}
-inline bool keyMatchesLowercasedUsemap(const AtomicStringImpl& key, Element* element)
+inline bool keyMatchesLowercasedUsemap(const AtomicStringImpl& key, const Element& element)
{
// FIXME: HTML5 specification says we should match both image and object elements.
- return isHTMLImageElement(element) && toHTMLImageElement(element)->matchesLowercasedUsemap(key);
+ return isHTMLImageElement(element) && toHTMLImageElement(element).matchesLowercasedUsemap(key);
}
-inline bool keyMatchesLabelForAttribute(const AtomicStringImpl& key, Element* element)
+inline bool keyMatchesLabelForAttribute(const AtomicStringImpl& key, const Element& element)
{
- return isHTMLLabelElement(element) && element->getAttribute(forAttr).impl() == &key;
+ return isHTMLLabelElement(element) && element.getAttribute(forAttr).impl() == &key;
}
-inline bool keyMatchesWindowNamedItem(const AtomicStringImpl& key, Element* element)
+inline bool keyMatchesWindowNamedItem(const AtomicStringImpl& key, const Element& element)
{
- return WindowNameCollection::nodeMatches(element, &key);
+ return WindowNameCollection::nodeMatches(const_cast<Element*>(&element), &key);
}
-inline bool keyMatchesDocumentNamedItem(const AtomicStringImpl& key, Element* element)
+inline bool keyMatchesDocumentNamedItem(const AtomicStringImpl& key, const Element& element)
{
- return DocumentNameCollection::nodeMatches(element, &key);
+ return DocumentNameCollection::nodeMatches(const_cast<Element*>(&element), &key);
}
void DocumentOrderedMap::clear()
@@ -99,7 +99,7 @@
MapEntry& entry = addResult.iterator->value;
ASSERT_WITH_SECURITY_IMPLICATION(entry.count);
- entry.element = 0;
+ entry.element = nullptr;
entry.count++;
entry.orderedList.clear();
}
@@ -119,20 +119,20 @@
m_map.remove(it);
} else {
if (entry.element == &element)
- entry.element = 0;
+ entry.element = nullptr;
entry.count--;
entry.orderedList.clear(); // FIXME: Remove the element instead if there are only few items left.
}
}
-template<bool keyMatches(const AtomicStringImpl&, Element*)>
+template<bool keyMatches(const AtomicStringImpl&, const Element&)>
inline Element* DocumentOrderedMap::get(const AtomicStringImpl& key, const TreeScope& scope) const
{
m_map.checkConsistency();
auto it = m_map.find(&key);
if (it == m_map.end())
- return 0;
+ return nullptr;
MapEntry& entry = it->value;
ASSERT(entry.count);
@@ -143,16 +143,16 @@
}
// We know there's at least one node that matches; iterate to find the first one.
- for (Element* element = ElementTraversal::firstWithin(scope.rootNode()); element; element = ElementTraversal::next(element)) {
+ for (auto& element : descendantsOfType<Element>(*scope.rootNode())) {
if (!keyMatches(key, element))
continue;
- entry.element = element;
- ASSERT_WITH_SECURITY_IMPLICATION(element->isInTreeScope());
- ASSERT_WITH_SECURITY_IMPLICATION(&element->treeScope() == &scope);
- return element;
+ entry.element = &element;
+ ASSERT_WITH_SECURITY_IMPLICATION(element.isInTreeScope());
+ ASSERT_WITH_SECURITY_IMPLICATION(&element.treeScope() == &scope);
+ return &element;
}
ASSERT_NOT_REACHED();
- return 0;
+ return nullptr;
}
Element* DocumentOrderedMap::getElementById(const AtomicStringImpl& key, const TreeScope& scope) const
@@ -201,19 +201,23 @@
auto it = m_map.find(&key);
if (it == m_map.end())
- return 0;
+ return nullptr;
MapEntry& entry = it->value;
ASSERT_WITH_SECURITY_IMPLICATION(entry.count);
if (!entry.count)
- return 0;
+ return nullptr;
if (entry.orderedList.isEmpty()) {
entry.orderedList.reserveCapacity(entry.count);
- for (Element* element = entry.element ? entry.element : ElementTraversal::firstWithin(scope.rootNode()); element; element = ElementTraversal::next(element)) {
+ auto elementDescandents = descendantsOfType<Element>(*scope.rootNode());
+ auto it = entry.element ? elementDescandents.find(*entry.element) : elementDescandents.begin();
+ auto end = elementDescandents.end();
+ for (; it != end; ++it) {
+ auto& element = *it;
if (!keyMatchesId(key, element))
continue;
- entry.orderedList.append(element);
+ entry.orderedList.append(&element);
}
ASSERT(entry.orderedList.size() == entry.count);
}
Modified: trunk/Source/WebCore/dom/DocumentOrderedMap.h (161571 => 161572)
--- trunk/Source/WebCore/dom/DocumentOrderedMap.h 2014-01-09 20:20:28 UTC (rev 161571)
+++ trunk/Source/WebCore/dom/DocumentOrderedMap.h 2014-01-09 20:22:06 UTC (rev 161572)
@@ -67,7 +67,7 @@
const Vector<Element*>* getAllElementsById(const AtomicStringImpl&, const TreeScope&) const;
private:
- template<bool keyMatches(const AtomicStringImpl&, Element*)> Element* get(const AtomicStringImpl&, const TreeScope&) const;
+ template<bool keyMatches(const AtomicStringImpl&, const Element&)> Element* get(const AtomicStringImpl&, const TreeScope&) const;
struct MapEntry {
MapEntry()