Changeset 161572 in webkit


Ignore:
Timestamp:
Jan 9, 2014, 12:22:06 PM (12 years ago)
Author:
Antti Koivisto
Message:

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:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/Source/WebCore/ChangeLog

    r161570 r161572  
     12014-01-09  Antti Koivisto  <antti@apple.com>
     2
     3        DocumentOrderedMap should use iterator
     4        https://bugs.webkit.org/show_bug.cgi?id=126696
     5
     6        Reviewed by Andreas Kling.
     7
     8        * dom/DocumentOrderedMap.cpp:
     9        (WebCore::keyMatchesId):
     10        (WebCore::keyMatchesName):
     11        (WebCore::keyMatchesMapName):
     12        (WebCore::keyMatchesLowercasedMapName):
     13        (WebCore::keyMatchesLowercasedUsemap):
     14        (WebCore::keyMatchesLabelForAttribute):
     15        (WebCore::keyMatchesWindowNamedItem):
     16        (WebCore::keyMatchesDocumentNamedItem):
     17       
     18            Switch to Element references.
     19
     20        (WebCore::DocumentOrderedMap::add):
     21        (WebCore::DocumentOrderedMap::remove):
     22        (WebCore::DocumentOrderedMap::get):
     23        (WebCore::DocumentOrderedMap::getAllElementsById):
     24       
     25             Use element iterator instead of ElementTraversal.
     26
     27        * dom/DocumentOrderedMap.h:
     28
    1292014-01-09  Beth Dakin  <bdakin@apple.com>
    230
  • TabularUnified trunk/Source/WebCore/dom/DocumentOrderedMap.cpp

    r159489 r161572  
    3232#include "DocumentOrderedMap.h"
    3333
    34 #include "ElementTraversal.h"
     34#include "ElementIterator.h"
    3535#include "HTMLImageElement.h"
    3636#include "HTMLLabelElement.h"
     
    4242using namespace HTMLNames;
    4343
    44 inline bool keyMatchesId(const AtomicStringImpl& key, Element* element)
    45 {
    46     return element->getIdAttribute().impl() == &key;
    47 }
    48 
    49 inline bool keyMatchesName(const AtomicStringImpl& key, Element* element)
    50 {
    51     return element->getNameAttribute().impl() == &key;
    52 }
    53 
    54 inline bool keyMatchesMapName(const AtomicStringImpl& key, Element* element)
    55 {
    56     return isHTMLMapElement(element) && toHTMLMapElement(element)->getName().impl() == &key;
    57 }
    58 
    59 inline bool keyMatchesLowercasedMapName(const AtomicStringImpl& key, Element* element)
    60 {
    61     return isHTMLMapElement(element) && toHTMLMapElement(element)->getName().lower().impl() == &key;
    62 }
    63 
    64 inline bool keyMatchesLowercasedUsemap(const AtomicStringImpl& key, Element* element)
     44inline bool keyMatchesId(const AtomicStringImpl& key, const Element& element)
     45{
     46    return element.getIdAttribute().impl() == &key;
     47}
     48
     49inline bool keyMatchesName(const AtomicStringImpl& key, const Element& element)
     50{
     51    return element.getNameAttribute().impl() == &key;
     52}
     53
     54inline bool keyMatchesMapName(const AtomicStringImpl& key, const Element& element)
     55{
     56    return isHTMLMapElement(element) && toHTMLMapElement(element).getName().impl() == &key;
     57}
     58
     59inline bool keyMatchesLowercasedMapName(const AtomicStringImpl& key, const Element& element)
     60{
     61    return isHTMLMapElement(element) && toHTMLMapElement(element).getName().lower().impl() == &key;
     62}
     63
     64inline bool keyMatchesLowercasedUsemap(const AtomicStringImpl& key, const Element& element)
    6565{
    6666    // FIXME: HTML5 specification says we should match both image and object elements.
    67     return isHTMLImageElement(element) && toHTMLImageElement(element)->matchesLowercasedUsemap(key);
    68 }
    69 
    70 inline bool keyMatchesLabelForAttribute(const AtomicStringImpl& key, Element* element)
    71 {
    72     return isHTMLLabelElement(element) && element->getAttribute(forAttr).impl() == &key;
    73 }
    74 
    75 inline bool keyMatchesWindowNamedItem(const AtomicStringImpl& key, Element* element)
    76 {
    77     return WindowNameCollection::nodeMatches(element, &key);
    78 }
    79 
    80 inline bool keyMatchesDocumentNamedItem(const AtomicStringImpl& key, Element* element)
    81 {
    82     return DocumentNameCollection::nodeMatches(element, &key);
     67    return isHTMLImageElement(element) && toHTMLImageElement(element).matchesLowercasedUsemap(key);
     68}
     69
     70inline bool keyMatchesLabelForAttribute(const AtomicStringImpl& key, const Element& element)
     71{
     72    return isHTMLLabelElement(element) && element.getAttribute(forAttr).impl() == &key;
     73}
     74
     75inline bool keyMatchesWindowNamedItem(const AtomicStringImpl& key, const Element& element)
     76{
     77    return WindowNameCollection::nodeMatches(const_cast<Element*>(&element), &key);
     78}
     79
     80inline bool keyMatchesDocumentNamedItem(const AtomicStringImpl& key, const Element& element)
     81{
     82    return DocumentNameCollection::nodeMatches(const_cast<Element*>(&element), &key);
    8383}
    8484
     
    100100    MapEntry& entry = addResult.iterator->value;
    101101    ASSERT_WITH_SECURITY_IMPLICATION(entry.count);
    102     entry.element = 0;
     102    entry.element = nullptr;
    103103    entry.count++;
    104104    entry.orderedList.clear();
     
    120120    } else {
    121121        if (entry.element == &element)
    122             entry.element = 0;
     122            entry.element = nullptr;
    123123        entry.count--;
    124124        entry.orderedList.clear(); // FIXME: Remove the element instead if there are only few items left.
     
    126126}
    127127
    128 template<bool keyMatches(const AtomicStringImpl&, Element*)>
     128template<bool keyMatches(const AtomicStringImpl&, const Element&)>
    129129inline Element* DocumentOrderedMap::get(const AtomicStringImpl& key, const TreeScope& scope) const
    130130{
     
    133133    auto it = m_map.find(&key);
    134134    if (it == m_map.end())
    135         return 0;
     135        return nullptr;
    136136
    137137    MapEntry& entry = it->value;
     
    144144
    145145    // We know there's at least one node that matches; iterate to find the first one.
    146     for (Element* element = ElementTraversal::firstWithin(scope.rootNode()); element; element = ElementTraversal::next(element)) {
     146    for (auto& element : descendantsOfType<Element>(*scope.rootNode())) {
    147147        if (!keyMatches(key, element))
    148148            continue;
    149         entry.element = element;
    150         ASSERT_WITH_SECURITY_IMPLICATION(element->isInTreeScope());
    151         ASSERT_WITH_SECURITY_IMPLICATION(&element->treeScope() == &scope);
    152         return element;
     149        entry.element = &element;
     150        ASSERT_WITH_SECURITY_IMPLICATION(element.isInTreeScope());
     151        ASSERT_WITH_SECURITY_IMPLICATION(&element.treeScope() == &scope);
     152        return &element;
    153153    }
    154154    ASSERT_NOT_REACHED();
    155     return 0;
     155    return nullptr;
    156156}
    157157
     
    202202    auto it = m_map.find(&key);
    203203    if (it == m_map.end())
    204         return 0;
     204        return nullptr;
    205205
    206206    MapEntry& entry = it->value;
    207207    ASSERT_WITH_SECURITY_IMPLICATION(entry.count);
    208208    if (!entry.count)
    209         return 0;
     209        return nullptr;
    210210
    211211    if (entry.orderedList.isEmpty()) {
    212212        entry.orderedList.reserveCapacity(entry.count);
    213         for (Element* element = entry.element ? entry.element : ElementTraversal::firstWithin(scope.rootNode()); element; element = ElementTraversal::next(element)) {
     213        auto elementDescandents = descendantsOfType<Element>(*scope.rootNode());
     214        auto it = entry.element ? elementDescandents.find(*entry.element) : elementDescandents.begin();
     215        auto end = elementDescandents.end();
     216        for (; it != end; ++it) {
     217            auto& element = *it;
    214218            if (!keyMatchesId(key, element))
    215219                continue;
    216             entry.orderedList.append(element);
     220            entry.orderedList.append(&element);
    217221        }
    218222        ASSERT(entry.orderedList.size() == entry.count);
  • TabularUnified trunk/Source/WebCore/dom/DocumentOrderedMap.h

    r159548 r161572  
    6868
    6969private:
    70     template<bool keyMatches(const AtomicStringImpl&, Element*)> Element* get(const AtomicStringImpl&, const TreeScope&) const;
     70    template<bool keyMatches(const AtomicStringImpl&, const Element&)> Element* get(const AtomicStringImpl&, const TreeScope&) const;
    7171
    7272    struct MapEntry {
Note: See TracChangeset for help on using the changeset viewer.