Changeset 161583 in webkit


Ignore:
Timestamp:
Jan 9, 2014, 2:10:22 PM (11 years ago)
Author:
Antti Koivisto
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):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r161577 r161583  
     12014-01-09  Antti Koivisto  <antti@apple.com>
     2
     3        Replace ElementIteratorAdapter find() with beginAt()
     4        https://bugs.webkit.org/show_bug.cgi?id=126714
     5
     6        Reviewed by Andreas Kling.
     7
     8        ElementIteratorAdapter find() would return iterator for the argument element if it was
     9        of correct type and in the right subtree. This is not really what you would expect from find()
     10        so replace it with a simple beginAt() iterator construction function.
     11
     12        * dom/DocumentOrderedMap.cpp:
     13        (WebCore::DocumentOrderedMap::getAllElementsById):
     14        * dom/ElementChildIterator.h:
     15        (WebCore::ElementChildIteratorAdapter<ElementType>::beginAt):
     16        (WebCore::ElementChildConstIteratorAdapter<ElementType>::beginAt):
     17        * dom/ElementDescendantIterator.h:
     18        (WebCore::ElementDescendantIteratorAdapter<ElementType>::beginAt):
     19        (WebCore::ElementDescendantConstIteratorAdapter<ElementType>::beginAt):
     20        * html/HTMLFormElement.cpp:
     21        (WebCore::HTMLFormElement::formElementIndex):
     22        * html/HTMLTableRowsCollection.cpp:
     23        (WebCore::HTMLTableRowsCollection::rowAfter):
     24
    1252014-01-09  Brian Burg  <bburg@apple.com>
    226
  • trunk/Source/WebCore/dom/DocumentOrderedMap.cpp

    r161572 r161583  
    212212        entry.orderedList.reserveCapacity(entry.count);
    213213        auto elementDescandents = descendantsOfType<Element>(*scope.rootNode());
    214         auto it = entry.element ? elementDescandents.find(*entry.element) : elementDescandents.begin();
     214        auto it = entry.element ? elementDescandents.beginAt(*entry.element) : elementDescandents.begin();
    215215        auto end = elementDescandents.end();
    216216        for (; it != end; ++it) {
  • trunk/Source/WebCore/dom/ElementChildIterator.h

    r161551 r161583  
    5454    ElementChildIterator<ElementType> begin();
    5555    ElementChildIterator<ElementType> end();
    56     ElementChildIterator<ElementType> find(Element&);
     56    ElementChildIterator<ElementType> beginAt(ElementType&);
    5757
    5858    ElementType* first();
     
    7070    ElementChildConstIterator<ElementType> begin() const;
    7171    ElementChildConstIterator<ElementType> end() const;
    72     ElementChildConstIterator<ElementType> find(const Element&) const;
     72    ElementChildConstIterator<ElementType> beginAt(const ElementType&) const;
    7373
    7474    const ElementType* first() const;
     
    155155
    156156template <typename ElementType>
    157 inline ElementChildIterator<ElementType> ElementChildIteratorAdapter<ElementType>::find(Element& child)
    158 {
    159     if (!isElementOfType<const ElementType>(child))
    160         return end();
    161     if (child.parentNode() != &m_parent)
    162         return end();
    163     return ElementChildIterator<ElementType>(m_parent, static_cast<ElementType*>(&child));
     157inline ElementChildIterator<ElementType> ElementChildIteratorAdapter<ElementType>::beginAt(ElementType& child)
     158{
     159    ASSERT(child.parentNode() == &m_parent);
     160    return ElementChildIterator<ElementType>(m_parent, &child);
    164161}
    165162
     
    197194
    198195template <typename ElementType>
    199 inline ElementChildConstIterator<ElementType> ElementChildConstIteratorAdapter<ElementType>::find(const Element& child) const
    200 {
    201     if (!isElementOfType<const ElementType>(child))
    202         return end();
    203     if (child.parentNode() != &m_parent)
    204         return end();
    205     return ElementChildConstIterator<ElementType>(m_parent, static_cast<const ElementType*>(&child));
     196inline ElementChildConstIterator<ElementType> ElementChildConstIteratorAdapter<ElementType>::beginAt(const ElementType& child) const
     197{
     198    ASSERT(child.parentNode() == &m_parent);
     199    return ElementChildConstIterator<ElementType>(m_parent, &child);
    206200}
    207201
  • trunk/Source/WebCore/dom/ElementDescendantIterator.h

    r161196 r161583  
    5353    ElementDescendantIterator<ElementType> begin();
    5454    ElementDescendantIterator<ElementType> end();
    55     ElementDescendantIterator<ElementType> find(Element&);
     55    ElementDescendantIterator<ElementType> beginAt(ElementType&);
    5656    ElementDescendantIterator<ElementType> from(Element&);
    5757
     
    6969    ElementDescendantConstIterator<ElementType> begin() const;
    7070    ElementDescendantConstIterator<ElementType> end() const;
    71     ElementDescendantConstIterator<ElementType> find(const Element&) const;
     71    ElementDescendantConstIterator<ElementType> beginAt(const ElementType&) const;
    7272    ElementDescendantConstIterator<ElementType> from(const Element&) const;
    7373
     
    144144   
    145145template <typename ElementType>
    146 inline ElementDescendantIterator<ElementType> ElementDescendantIteratorAdapter<ElementType>::find(Element& descendant)
    147 {
    148     if (!isElementOfType<const ElementType>(descendant))
    149         return end();
    150     if (!descendant.isDescendantOf(&m_root))
    151         return end();
     146inline ElementDescendantIterator<ElementType> ElementDescendantIteratorAdapter<ElementType>::beginAt(ElementType& descendant)
     147{
     148    ASSERT(descendant.isDescendantOf(&m_root));
    152149    return ElementDescendantIterator<ElementType>(m_root, static_cast<ElementType*>(&descendant));
    153150}
     
    196193
    197194template <typename ElementType>
    198 inline ElementDescendantConstIterator<ElementType> ElementDescendantConstIteratorAdapter<ElementType>::find(const Element& descendant) const
    199 {
    200     if (!isElementOfType<const ElementType>(descendant))
    201         return end();
    202     if (!descendant.isDescendantOf(&m_root))
    203         return end();
    204     return ElementDescendantConstIterator<ElementType>(m_root, static_cast<const ElementType*>(&descendant));
     195inline ElementDescendantConstIterator<ElementType> ElementDescendantConstIteratorAdapter<ElementType>::beginAt(const ElementType& descendant) const
     196{
     197    ASSERT(descendant.isDescendantOf(&m_root));
     198    return ElementDescendantConstIterator<ElementType>(m_root, &descendant);
    205199}
    206200
  • trunk/Source/WebCore/html/HTMLFormElement.cpp

    r161166 r161583  
    505505    ++m_associatedElementsAfterIndex;
    506506
     507    if (!associatedHTMLElement.isDescendantOf(this))
     508        return currentAssociatedElementsAfterIndex;
     509
    507510    // Check for the special case where this element is the very last thing in
    508511    // the form's tree of children; we don't want to walk the entire tree in that
     
    510513    // that says "add this form element to the end of the array".
    511514    auto descendants = descendantsOfType<HTMLElement>(*this);
    512     auto it = descendants.find(associatedHTMLElement);
     515    auto it = descendants.beginAt(associatedHTMLElement);
    513516    auto end = descendants.end();
    514     if (it == end || ++it == end)
     517    if (++it == end)
    515518        return currentAssociatedElementsAfterIndex;
    516519
  • trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp

    r161551 r161583  
    7171    // Start by looking for the next row in this section. Continue only if there is none.
    7272    if (previous && previous->parentNode() != table) {
    73         auto rows = childrenOfType<HTMLTableRowElement>(*previous->parentNode());
    74         auto row = rows.find(*previous);
    75         if (++row != rows.end())
     73        auto childRows = childrenOfType<HTMLTableRowElement>(*previous->parentNode());
     74        auto row = childRows.beginAt(*previous);
     75        if (++row != childRows.end())
    7676            return &*row;
    7777    }
Note: See TracChangeset for help on using the changeset viewer.