Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: Source/core/dom/LiveNodeListBase.h

Issue 224303004: Stop passing the root node to node lists traversal functions (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/LiveNodeList.cpp ('k') | Source/core/html/CollectionIndexCache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
6 * Copyright (C) 2014 Samsung Electronics. All rights reserved. 6 * Copyright (C) 2014 Samsung Electronics. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType, const QualifiedName&); 80 static bool shouldInvalidateTypeOnAttributeChange(NodeListInvalidationType, const QualifiedName&);
81 81
82 protected: 82 protected:
83 Document& document() const { return m_ownerNode->document(); } 83 Document& document() const { return m_ownerNode->document(); }
84 84
85 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis tRootType>(m_rootType); } 85 ALWAYS_INLINE NodeListRootType rootType() const { return static_cast<NodeLis tRootType>(m_rootType); }
86 86
87 template <typename Collection> 87 template <typename Collection>
88 static Element* itemBefore(const Collection&, const Element* previousItem); 88 static Element* itemBefore(const Collection&, const Element* previousItem);
89 template <class NodeListType> 89 template <class NodeListType>
90 static Element* firstMatchingElement(const NodeListType&, const ContainerNod e&); 90 static Element* firstMatchingElement(const NodeListType&);
91 template <class NodeListType> 91 template <class NodeListType>
92 static Element* nextMatchingElement(const NodeListType&, Element& current, c onst ContainerNode& root); 92 static Element* nextMatchingElement(const NodeListType&, Element& current);
93 template <class NodeListType> 93 template <class NodeListType>
94 static Element* traverseMatchingElementsForwardToOffset(const NodeListType&, unsigned offset, Element& currentElement, unsigned& currentOffset, const Contai nerNode& root); 94 static Element* traverseMatchingElementsForwardToOffset(const NodeListType&, unsigned offset, Element& currentElement, unsigned& currentOffset);
95 95
96 private: 96 private:
97 void invalidateIdNameCacheMaps() const; 97 void invalidateIdNameCacheMaps() const;
98 template <typename Collection> 98 template <typename Collection>
99 static Element* iterateForPreviousNode(const Collection&, Node* current); 99 static Element* iterateForPreviousNode(const Collection&, Node* current);
100 static Node* previousNode(const ContainerNode&, const Node& previous, bool o nlyIncludeDirectChildren); 100 static Node* previousNode(const ContainerNode&, const Node& previous, bool o nlyIncludeDirectChildren);
101 static Node* lastDescendant(const ContainerNode&); 101 static Node* lastDescendant(const ContainerNode&);
102 static Node* lastNode(const ContainerNode&, bool onlyIncludeDirectChildren); 102 static Node* lastNode(const ContainerNode&, bool onlyIncludeDirectChildren);
103 103
104 RefPtr<ContainerNode> m_ownerNode; // Cannot be null. 104 RefPtr<ContainerNode> m_ownerNode; // Cannot be null.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 Node* current; 167 Node* current;
168 if (LIKELY(!!previous)) // Without this LIKELY, length() and item() can be 1 0% slower. 168 if (LIKELY(!!previous)) // Without this LIKELY, length() and item() can be 1 0% slower.
169 current = previousNode(collection.rootNode(), *previous, collection.shou ldOnlyIncludeDirectChildren()); 169 current = previousNode(collection.rootNode(), *previous, collection.shou ldOnlyIncludeDirectChildren());
170 else 170 else
171 current = lastNode(collection.rootNode(), collection.shouldOnlyIncludeDi rectChildren()); 171 current = lastNode(collection.rootNode(), collection.shouldOnlyIncludeDi rectChildren());
172 172
173 return iterateForPreviousNode(collection, current); 173 return iterateForPreviousNode(collection, current);
174 } 174 }
175 175
176 template <class NodeListType> 176 template <class NodeListType>
177 Element* LiveNodeListBase::firstMatchingElement(const NodeListType& nodeList, co nst ContainerNode& root) 177 Element* LiveNodeListBase::firstMatchingElement(const NodeListType& nodeList)
178 { 178 {
179 ContainerNode& root = nodeList.rootNode();
179 Element* element = ElementTraversal::firstWithin(root); 180 Element* element = ElementTraversal::firstWithin(root);
180 while (element && !isMatchingElement(nodeList, *element)) 181 while (element && !isMatchingElement(nodeList, *element))
181 element = ElementTraversal::next(*element, &root); 182 element = ElementTraversal::next(*element, &root);
182 return element; 183 return element;
183 } 184 }
184 185
185 template <class NodeListType> 186 template <class NodeListType>
186 Element* LiveNodeListBase::nextMatchingElement(const NodeListType& nodeList, Ele ment& current, const ContainerNode& root) 187 Element* LiveNodeListBase::nextMatchingElement(const NodeListType& nodeList, Ele ment& current)
187 { 188 {
189 ContainerNode& root = nodeList.rootNode();
188 Element* next = &current; 190 Element* next = &current;
189 do { 191 do {
190 next = ElementTraversal::next(*next, &root); 192 next = ElementTraversal::next(*next, &root);
191 } while (next && !isMatchingElement(nodeList, *next)); 193 } while (next && !isMatchingElement(nodeList, *next));
192 return next; 194 return next;
193 } 195 }
194 196
195 template <class NodeListType> 197 template <class NodeListType>
196 Element* LiveNodeListBase::traverseMatchingElementsForwardToOffset(const NodeLis tType& nodeList, unsigned offset, Element& currentElement, unsigned& currentOffs et, const ContainerNode& root) 198 Element* LiveNodeListBase::traverseMatchingElementsForwardToOffset(const NodeLis tType& nodeList, unsigned offset, Element& currentElement, unsigned& currentOffs et)
197 { 199 {
198 ASSERT(currentOffset < offset); 200 ASSERT(currentOffset < offset);
199 Element* next = &currentElement; 201 Element* next = &currentElement;
200 while ((next = nextMatchingElement(nodeList, *next, root))) { 202 while ((next = nextMatchingElement(nodeList, *next))) {
201 if (++currentOffset == offset) 203 if (++currentOffset == offset)
202 return next; 204 return next;
203 } 205 }
204 return 0; 206 return 0;
205 } 207 }
206 208
207 } // namespace WebCore 209 } // namespace WebCore
208 210
209 #endif // LiveNodeListBase_h 211 #endif // LiveNodeListBase_h
OLDNEW
« no previous file with comments | « Source/core/dom/LiveNodeList.cpp ('k') | Source/core/html/CollectionIndexCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698