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

Side by Side Diff: Source/core/css/SiblingTraversalStrategies.h

Issue 18276003: Avoid N^2 walk placing renderers when building the render tree (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Removing extra parens (whoops) Created 7 years, 5 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/css/SelectorChecker.cpp ('k') | Source/core/css/resolver/StyleResolver.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) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) { 71 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) {
72 if (sibling->hasTagName(type)) 72 if (sibling->hasTagName(type))
73 return false; 73 return false;
74 } 74 }
75 return true; 75 return true;
76 } 76 }
77 77
78 inline int DOMSiblingTraversalStrategy::countElementsBefore(Element* element) co nst 78 inline int DOMSiblingTraversalStrategy::countElementsBefore(Element* element) co nst
79 { 79 {
80 int count = 0; 80 int count = 0;
81 for (const Element* sibling = element->previousElementSibling(); sibling; si bling = sibling->previousElementSibling()) { 81 // We can't use the same early return as is present in countElementsAfter du e
82 unsigned index = sibling->childIndex(); 82 // to the order we resolve style; if a new element is inserted into the midd le,
83 if (index) { 83 // we'd end up using a stale cached childIndex.
84 count += index; 84 for (const Element* sibling = element->previousElementSibling(); sibling; si bling = sibling->previousElementSibling())
85 break; 85 ++count;
86 }
87 count++;
88 }
89 86
90 return count; 87 return count;
91 } 88 }
92 89
93 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element* eleme nt, const QualifiedName& type) const 90 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element* eleme nt, const QualifiedName& type) const
94 { 91 {
95 int count = 0; 92 int count = 0;
96 for (const Element* sibling = element->previousElementSibling(); sibling; si bling = sibling->previousElementSibling()) { 93 for (const Element* sibling = element->previousElementSibling(); sibling; si bling = sibling->previousElementSibling()) {
97 if (sibling->hasTagName(type)) 94 if (sibling->hasTagName(type))
98 ++count; 95 ++count;
99 } 96 }
100 97
101 return count; 98 return count;
102 } 99 }
103 100
104 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element* element) con st 101 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element* element) con st
105 { 102 {
106 int count = 0; 103 int count = 0;
107 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) 104 // We can use an early return here because we resolve style from lastChild t o
105 // firstChild, so we're guaranteed to not have stale cached childIndices.
106 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) {
107 unsigned index = sibling->childIndex();
108 if (index) {
109 count += index;
110 break;
111 }
108 ++count; 112 ++count;
113 }
109 114
110 return count; 115 return count;
111 } 116 }
112 117
113 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element* elemen t, const QualifiedName& type) const 118 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element* elemen t, const QualifiedName& type) const
114 { 119 {
115 int count = 0; 120 int count = 0;
116 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) { 121 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) {
117 if (sibling->hasTagName(type)) 122 if (sibling->hasTagName(type))
118 ++count; 123 ++count;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 if (siblings[i] && siblings[i]->isElementNode() && siblings[i]->hasTagNa me(type)) 268 if (siblings[i] && siblings[i]->isElementNode() && siblings[i]->hasTagNa me(type))
264 return ++count; 269 return ++count;
265 } 270 }
266 271
267 return count; 272 return count;
268 } 273 }
269 274
270 } 275 }
271 276
272 #endif 277 #endif
OLDNEW
« no previous file with comments | « Source/core/css/SelectorChecker.cpp ('k') | Source/core/css/resolver/StyleResolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698