Title: [161583] trunk/Source/WebCore
Revision
161583
Author
[email protected]
Date
2014-01-09 14:10:22 -0800 (Thu, 09 Jan 2014)

Log Message

Replace ElementIteratorAdapter find() with beginAt()
https://bugs.webkit.org/show_bug.cgi?id=126714

Reviewed by Andreas Kling.

ElementIteratorAdapter find() would return iterator for the argument element if it was
of correct type and in the right subtree. This is not really what you would expect from find()
so replace it with a simple beginAt() iterator construction function.

* dom/DocumentOrderedMap.cpp:
(WebCore::DocumentOrderedMap::getAllElementsById):
* dom/ElementChildIterator.h:
(WebCore::ElementChildIteratorAdapter<ElementType>::beginAt):
(WebCore::ElementChildConstIteratorAdapter<ElementType>::beginAt):
* dom/ElementDescendantIterator.h:
(WebCore::ElementDescendantIteratorAdapter<ElementType>::beginAt):
(WebCore::ElementDescendantConstIteratorAdapter<ElementType>::beginAt):
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::formElementIndex):
* html/HTMLTableRowsCollection.cpp:
(WebCore::HTMLTableRowsCollection::rowAfter):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (161582 => 161583)


--- trunk/Source/WebCore/ChangeLog	2014-01-09 22:07:31 UTC (rev 161582)
+++ trunk/Source/WebCore/ChangeLog	2014-01-09 22:10:22 UTC (rev 161583)
@@ -1,3 +1,27 @@
+2014-01-09  Antti Koivisto  <[email protected]>
+
+        Replace ElementIteratorAdapter find() with beginAt()
+        https://bugs.webkit.org/show_bug.cgi?id=126714
+
+        Reviewed by Andreas Kling.
+
+        ElementIteratorAdapter find() would return iterator for the argument element if it was
+        of correct type and in the right subtree. This is not really what you would expect from find()
+        so replace it with a simple beginAt() iterator construction function.
+
+        * dom/DocumentOrderedMap.cpp:
+        (WebCore::DocumentOrderedMap::getAllElementsById):
+        * dom/ElementChildIterator.h:
+        (WebCore::ElementChildIteratorAdapter<ElementType>::beginAt):
+        (WebCore::ElementChildConstIteratorAdapter<ElementType>::beginAt):
+        * dom/ElementDescendantIterator.h:
+        (WebCore::ElementDescendantIteratorAdapter<ElementType>::beginAt):
+        (WebCore::ElementDescendantConstIteratorAdapter<ElementType>::beginAt):
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::formElementIndex):
+        * html/HTMLTableRowsCollection.cpp:
+        (WebCore::HTMLTableRowsCollection::rowAfter):
+
 2014-01-09  Brian Burg  <[email protected]>
 
         REGRESSION (r160152): Selection drag snapshot doesn't appear or has the wrong content on Retina

Modified: trunk/Source/WebCore/dom/DocumentOrderedMap.cpp (161582 => 161583)


--- trunk/Source/WebCore/dom/DocumentOrderedMap.cpp	2014-01-09 22:07:31 UTC (rev 161582)
+++ trunk/Source/WebCore/dom/DocumentOrderedMap.cpp	2014-01-09 22:10:22 UTC (rev 161583)
@@ -211,7 +211,7 @@
     if (entry.orderedList.isEmpty()) {
         entry.orderedList.reserveCapacity(entry.count);
         auto elementDescandents = descendantsOfType<Element>(*scope.rootNode());
-        auto it = entry.element ? elementDescandents.find(*entry.element) : elementDescandents.begin();
+        auto it = entry.element ? elementDescandents.beginAt(*entry.element) : elementDescandents.begin();
         auto end = elementDescandents.end();
         for (; it != end; ++it) {
             auto& element = *it;

Modified: trunk/Source/WebCore/dom/ElementChildIterator.h (161582 => 161583)


--- trunk/Source/WebCore/dom/ElementChildIterator.h	2014-01-09 22:07:31 UTC (rev 161582)
+++ trunk/Source/WebCore/dom/ElementChildIterator.h	2014-01-09 22:10:22 UTC (rev 161583)
@@ -53,7 +53,7 @@
 
     ElementChildIterator<ElementType> begin();
     ElementChildIterator<ElementType> end();
-    ElementChildIterator<ElementType> find(Element&);
+    ElementChildIterator<ElementType> beginAt(ElementType&);
 
     ElementType* first();
     ElementType* last();
@@ -69,7 +69,7 @@
 
     ElementChildConstIterator<ElementType> begin() const;
     ElementChildConstIterator<ElementType> end() const;
-    ElementChildConstIterator<ElementType> find(const Element&) const;
+    ElementChildConstIterator<ElementType> beginAt(const ElementType&) const;
 
     const ElementType* first() const;
     const ElementType* last() const;
@@ -154,13 +154,10 @@
 }
 
 template <typename ElementType>
-inline ElementChildIterator<ElementType> ElementChildIteratorAdapter<ElementType>::find(Element& child)
+inline ElementChildIterator<ElementType> ElementChildIteratorAdapter<ElementType>::beginAt(ElementType& child)
 {
-    if (!isElementOfType<const ElementType>(child))
-        return end();
-    if (child.parentNode() != &m_parent)
-        return end();
-    return ElementChildIterator<ElementType>(m_parent, static_cast<ElementType*>(&child));
+    ASSERT(child.parentNode() == &m_parent);
+    return ElementChildIterator<ElementType>(m_parent, &child);
 }
 
 // ElementChildConstIteratorAdapter
@@ -196,13 +193,10 @@
 }
 
 template <typename ElementType>
-inline ElementChildConstIterator<ElementType> ElementChildConstIteratorAdapter<ElementType>::find(const Element& child) const
+inline ElementChildConstIterator<ElementType> ElementChildConstIteratorAdapter<ElementType>::beginAt(const ElementType& child) const
 {
-    if (!isElementOfType<const ElementType>(child))
-        return end();
-    if (child.parentNode() != &m_parent)
-        return end();
-    return ElementChildConstIterator<ElementType>(m_parent, static_cast<const ElementType*>(&child));
+    ASSERT(child.parentNode() == &m_parent);
+    return ElementChildConstIterator<ElementType>(m_parent, &child);
 }
 
 // Standalone functions

Modified: trunk/Source/WebCore/dom/ElementDescendantIterator.h (161582 => 161583)


--- trunk/Source/WebCore/dom/ElementDescendantIterator.h	2014-01-09 22:07:31 UTC (rev 161582)
+++ trunk/Source/WebCore/dom/ElementDescendantIterator.h	2014-01-09 22:10:22 UTC (rev 161583)
@@ -52,7 +52,7 @@
     ElementDescendantIteratorAdapter(ContainerNode& root);
     ElementDescendantIterator<ElementType> begin();
     ElementDescendantIterator<ElementType> end();
-    ElementDescendantIterator<ElementType> find(Element&);
+    ElementDescendantIterator<ElementType> beginAt(ElementType&);
     ElementDescendantIterator<ElementType> from(Element&);
 
     ElementType* first();
@@ -68,7 +68,7 @@
     ElementDescendantConstIteratorAdapter(const ContainerNode& root);
     ElementDescendantConstIterator<ElementType> begin() const;
     ElementDescendantConstIterator<ElementType> end() const;
-    ElementDescendantConstIterator<ElementType> find(const Element&) const;
+    ElementDescendantConstIterator<ElementType> beginAt(const ElementType&) const;
     ElementDescendantConstIterator<ElementType> from(const Element&) const;
 
     const ElementType* first() const;
@@ -143,12 +143,9 @@
 }
     
 template <typename ElementType>
-inline ElementDescendantIterator<ElementType> ElementDescendantIteratorAdapter<ElementType>::find(Element& descendant)
+inline ElementDescendantIterator<ElementType> ElementDescendantIteratorAdapter<ElementType>::beginAt(ElementType& descendant)
 {
-    if (!isElementOfType<const ElementType>(descendant))
-        return end();
-    if (!descendant.isDescendantOf(&m_root))
-        return end();
+    ASSERT(descendant.isDescendantOf(&m_root));
     return ElementDescendantIterator<ElementType>(m_root, static_cast<ElementType*>(&descendant));
 }
 
@@ -195,13 +192,10 @@
 }
 
 template <typename ElementType>
-inline ElementDescendantConstIterator<ElementType> ElementDescendantConstIteratorAdapter<ElementType>::find(const Element& descendant) const
+inline ElementDescendantConstIterator<ElementType> ElementDescendantConstIteratorAdapter<ElementType>::beginAt(const ElementType& descendant) const
 {
-    if (!isElementOfType<const ElementType>(descendant))
-        return end();
-    if (!descendant.isDescendantOf(&m_root))
-        return end();
-    return ElementDescendantConstIterator<ElementType>(m_root, static_cast<const ElementType*>(&descendant));
+    ASSERT(descendant.isDescendantOf(&m_root));
+    return ElementDescendantConstIterator<ElementType>(m_root, &descendant);
 }
 
 template <typename ElementType>

Modified: trunk/Source/WebCore/html/HTMLFormElement.cpp (161582 => 161583)


--- trunk/Source/WebCore/html/HTMLFormElement.cpp	2014-01-09 22:07:31 UTC (rev 161582)
+++ trunk/Source/WebCore/html/HTMLFormElement.cpp	2014-01-09 22:10:22 UTC (rev 161583)
@@ -504,14 +504,17 @@
     unsigned currentAssociatedElementsAfterIndex = m_associatedElementsAfterIndex;
     ++m_associatedElementsAfterIndex;
 
+    if (!associatedHTMLElement.isDescendantOf(this))
+        return currentAssociatedElementsAfterIndex;
+
     // Check for the special case where this element is the very last thing in
     // the form's tree of children; we don't want to walk the entire tree in that
     // common case that occurs during parsing; instead we'll just return a value
     // that says "add this form element to the end of the array".
     auto descendants = descendantsOfType<HTMLElement>(*this);
-    auto it = descendants.find(associatedHTMLElement);
+    auto it = descendants.beginAt(associatedHTMLElement);
     auto end = descendants.end();
-    if (it == end || ++it == end)
+    if (++it == end)
         return currentAssociatedElementsAfterIndex;
 
     unsigned i = m_associatedElementsBeforeIndex;

Modified: trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp (161582 => 161583)


--- trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp	2014-01-09 22:07:31 UTC (rev 161582)
+++ trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp	2014-01-09 22:10:22 UTC (rev 161583)
@@ -70,9 +70,9 @@
 
     // Start by looking for the next row in this section. Continue only if there is none.
     if (previous && previous->parentNode() != table) {
-        auto rows = childrenOfType<HTMLTableRowElement>(*previous->parentNode());
-        auto row = rows.find(*previous);
-        if (++row != rows.end())
+        auto childRows = childrenOfType<HTMLTableRowElement>(*previous->parentNode());
+        auto row = childRows.beginAt(*previous);
+        if (++row != childRows.end())
             return &*row;
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to