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

Side by Side Diff: third_party/WebKit/Source/core/dom/NthIndexCache.cpp

Issue 2390543002: Reflow comments in core/dom/. (Closed)
Patch Set: Reformat comments in core/dom/. Created 4 years, 2 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/NthIndexCache.h" 5 #include "core/dom/NthIndexCache.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/ElementTraversal.h" 8 #include "core/dom/ElementTraversal.h"
9 9
10 namespace blink { 10 namespace blink {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 unsigned NthIndexData::nthLastIndex(Element& element) const { 216 unsigned NthIndexData::nthLastIndex(Element& element) const {
217 return m_count - nthIndex(element) + 1; 217 return m_count - nthIndex(element) + 1;
218 } 218 }
219 219
220 unsigned NthIndexData::nthLastOfTypeIndex(Element& element) const { 220 unsigned NthIndexData::nthLastOfTypeIndex(Element& element) const {
221 return m_count - nthOfTypeIndex(element) + 1; 221 return m_count - nthOfTypeIndex(element) + 1;
222 } 222 }
223 223
224 NthIndexData::NthIndexData(ContainerNode& parent) { 224 NthIndexData::NthIndexData(ContainerNode& parent) {
225 // The frequency at which we cache the nth-index for a set of siblings. 225 // The frequency at which we cache the nth-index for a set of siblings. A
226 // A spread value of 3 means every third Element will have its nth-index cache d. 226 // spread value of 3 means every third Element will have its nth-index cached.
227 // Using a spread value > 1 is done to save memory. Looking up the nth-index w ill 227 // Using a spread value > 1 is done to save memory. Looking up the nth-index
228 // still be done in constant time in terms of sibling count, at most 'spread' 228 // will still be done in constant time in terms of sibling count, at most
229 // elements will be traversed. 229 // 'spread' elements will be traversed.
230 const unsigned spread = 3; 230 const unsigned spread = 3;
231 unsigned count = 0; 231 unsigned count = 0;
232 for (Element* sibling = ElementTraversal::firstChild(parent); sibling; 232 for (Element* sibling = ElementTraversal::firstChild(parent); sibling;
233 sibling = ElementTraversal::nextSibling(*sibling)) { 233 sibling = ElementTraversal::nextSibling(*sibling)) {
234 if (!(++count % spread)) 234 if (!(++count % spread))
235 m_elementIndexMap.add(sibling, count); 235 m_elementIndexMap.add(sibling, count);
236 } 236 }
237 DCHECK(count); 237 DCHECK(count);
238 m_count = count; 238 m_count = count;
239 } 239 }
240 240
241 NthIndexData::NthIndexData(ContainerNode& parent, const QualifiedName& type) { 241 NthIndexData::NthIndexData(ContainerNode& parent, const QualifiedName& type) {
242 // The frequency at which we cache the nth-index of type for a set of siblings . 242 // The frequency at which we cache the nth-index of type for a set of
243 // A spread value of 3 means every third Element of its type will have its nth -index cached. 243 // siblings. A spread value of 3 means every third Element of its type will
244 // Using a spread value > 1 is done to save memory. Looking up the nth-index o f its type will 244 // have its nth-index cached. Using a spread value > 1 is done to save
245 // still be done in less time, as most number of elements traversed 245 // memory. Looking up the nth-index of its type will still be done in less
246 // will be equal to find 'spread' elements in the sibling set. 246 // time, as most number of elements traversed will be equal to find 'spread'
247 // elements in the sibling set.
247 const unsigned spread = 3; 248 const unsigned spread = 3;
248 unsigned count = 0; 249 unsigned count = 0;
249 for (Element* sibling = 250 for (Element* sibling =
250 ElementTraversal::firstChild(parent, HasTagName(type)); 251 ElementTraversal::firstChild(parent, HasTagName(type));
251 sibling; 252 sibling;
252 sibling = ElementTraversal::nextSibling(*sibling, HasTagName(type))) { 253 sibling = ElementTraversal::nextSibling(*sibling, HasTagName(type))) {
253 if (!(++count % spread)) 254 if (!(++count % spread))
254 m_elementIndexMap.add(sibling, count); 255 m_elementIndexMap.add(sibling, count);
255 } 256 }
256 DCHECK(count); 257 DCHECK(count);
257 m_count = count; 258 m_count = count;
258 } 259 }
259 260
260 DEFINE_TRACE(NthIndexData) { 261 DEFINE_TRACE(NthIndexData) {
261 visitor->trace(m_elementIndexMap); 262 visitor->trace(m_elementIndexMap);
262 } 263 }
263 264
264 } // namespace blink 265 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/NodeTraversal.cpp ('k') | third_party/WebKit/Source/core/dom/PendingScript.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698