Changeset 161572 in webkit
- Timestamp:
- Jan 9, 2014, 12:22:06 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/Source/WebCore/ChangeLog ¶
r161570 r161572 1 2014-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 1 29 2014-01-09 Beth Dakin <bdakin@apple.com> 2 30 -
TabularUnified trunk/Source/WebCore/dom/DocumentOrderedMap.cpp ¶
r159489 r161572 32 32 #include "DocumentOrderedMap.h" 33 33 34 #include "Element Traversal.h"34 #include "ElementIterator.h" 35 35 #include "HTMLImageElement.h" 36 36 #include "HTMLLabelElement.h" … … 42 42 using namespace HTMLNames; 43 43 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)44 inline bool keyMatchesId(const AtomicStringImpl& key, const Element& element) 45 { 46 return element.getIdAttribute().impl() == &key; 47 } 48 49 inline bool keyMatchesName(const AtomicStringImpl& key, const Element& element) 50 { 51 return element.getNameAttribute().impl() == &key; 52 } 53 54 inline bool keyMatchesMapName(const AtomicStringImpl& key, const Element& element) 55 { 56 return isHTMLMapElement(element) && toHTMLMapElement(element).getName().impl() == &key; 57 } 58 59 inline bool keyMatchesLowercasedMapName(const AtomicStringImpl& key, const Element& element) 60 { 61 return isHTMLMapElement(element) && toHTMLMapElement(element).getName().lower().impl() == &key; 62 } 63 64 inline bool keyMatchesLowercasedUsemap(const AtomicStringImpl& key, const Element& element) 65 65 { 66 66 // 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 70 inline bool keyMatchesLabelForAttribute(const AtomicStringImpl& key, const Element& element) 71 { 72 return isHTMLLabelElement(element) && element.getAttribute(forAttr).impl() == &key; 73 } 74 75 inline bool keyMatchesWindowNamedItem(const AtomicStringImpl& key, const Element& element) 76 { 77 return WindowNameCollection::nodeMatches(const_cast<Element*>(&element), &key); 78 } 79 80 inline bool keyMatchesDocumentNamedItem(const AtomicStringImpl& key, const Element& element) 81 { 82 return DocumentNameCollection::nodeMatches(const_cast<Element*>(&element), &key); 83 83 } 84 84 … … 100 100 MapEntry& entry = addResult.iterator->value; 101 101 ASSERT_WITH_SECURITY_IMPLICATION(entry.count); 102 entry.element = 0;102 entry.element = nullptr; 103 103 entry.count++; 104 104 entry.orderedList.clear(); … … 120 120 } else { 121 121 if (entry.element == &element) 122 entry.element = 0;122 entry.element = nullptr; 123 123 entry.count--; 124 124 entry.orderedList.clear(); // FIXME: Remove the element instead if there are only few items left. … … 126 126 } 127 127 128 template<bool keyMatches(const AtomicStringImpl&, Element*)>128 template<bool keyMatches(const AtomicStringImpl&, const Element&)> 129 129 inline Element* DocumentOrderedMap::get(const AtomicStringImpl& key, const TreeScope& scope) const 130 130 { … … 133 133 auto it = m_map.find(&key); 134 134 if (it == m_map.end()) 135 return 0;135 return nullptr; 136 136 137 137 MapEntry& entry = it->value; … … 144 144 145 145 // 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())) { 147 147 if (!keyMatches(key, element)) 148 148 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; 153 153 } 154 154 ASSERT_NOT_REACHED(); 155 return 0;155 return nullptr; 156 156 } 157 157 … … 202 202 auto it = m_map.find(&key); 203 203 if (it == m_map.end()) 204 return 0;204 return nullptr; 205 205 206 206 MapEntry& entry = it->value; 207 207 ASSERT_WITH_SECURITY_IMPLICATION(entry.count); 208 208 if (!entry.count) 209 return 0;209 return nullptr; 210 210 211 211 if (entry.orderedList.isEmpty()) { 212 212 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; 214 218 if (!keyMatchesId(key, element)) 215 219 continue; 216 entry.orderedList.append( element);220 entry.orderedList.append(&element); 217 221 } 218 222 ASSERT(entry.orderedList.size() == entry.count); -
TabularUnified trunk/Source/WebCore/dom/DocumentOrderedMap.h ¶
r159548 r161572 68 68 69 69 private: 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; 71 71 72 72 struct MapEntry {
Note:
See TracChangeset
for help on using the changeset viewer.