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

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

Issue 15871005: Avoid N^2 walk placing renderers when building the render tree (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Reversing the snapshotting logic to fix a bug, and updating test expectations. Created 7 years, 6 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 /* 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) { 72 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) {
73 if (sibling->hasTagName(type)) 73 if (sibling->hasTagName(type))
74 return false; 74 return false;
75 } 75 }
76 return true; 76 return true;
77 } 77 }
78 78
79 inline int DOMSiblingTraversalStrategy::countElementsBefore(Element* element) co nst 79 inline int DOMSiblingTraversalStrategy::countElementsBefore(Element* element) co nst
80 { 80 {
81 int count = 0; 81 int count = 0;
82 for (const Element* sibling = element->previousElementSibling(); sibling; si bling = sibling->previousElementSibling()) { 82 // We can't use the same early return as is present in countElementsAfter du e
83 unsigned index = sibling->childIndex(); 83 // to the order we resolve style; if a new element is inserted into the midd le,
84 if (index) { 84 // we'd end up using a stale cached childIndex.
85 count += index; 85 for (const Element* sibling = element->previousElementSibling(); sibling; si bling = sibling->previousElementSibling())
86 break; 86 ++count;
esprehn 2013/06/05 00:12:26 Lets watch the perf bots for this one.
87 }
88 count++;
89 }
90 87
91 return count; 88 return count;
92 } 89 }
93 90
94 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element* eleme nt, const QualifiedName& type) const 91 inline int DOMSiblingTraversalStrategy::countElementsOfTypeBefore(Element* eleme nt, const QualifiedName& type) const
95 { 92 {
96 int count = 0; 93 int count = 0;
97 for (const Element* sibling = element->previousElementSibling(); sibling; si bling = sibling->previousElementSibling()) { 94 for (const Element* sibling = element->previousElementSibling(); sibling; si bling = sibling->previousElementSibling()) {
98 if (sibling->hasTagName(type)) 95 if (sibling->hasTagName(type))
99 ++count; 96 ++count;
100 } 97 }
101 98
102 return count; 99 return count;
103 } 100 }
104 101
105 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element* element) con st 102 inline int DOMSiblingTraversalStrategy::countElementsAfter(Element* element) con st
106 { 103 {
107 int count = 0; 104 int count = 0;
108 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) 105 // We can use an early return here because we resolve style from lastChild t o
106 // firstChild, so we're guaranteed to not have stale cached childIndices.
107 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) {
108 unsigned index = sibling->childIndex();
109 if (index) {
110 count += index;
111 break;
112 }
109 ++count; 113 ++count;
114 }
110 115
111 return count; 116 return count;
112 } 117 }
113 118
114 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element* elemen t, const QualifiedName& type) const 119 inline int DOMSiblingTraversalStrategy::countElementsOfTypeAfter(Element* elemen t, const QualifiedName& type) const
115 { 120 {
116 int count = 0; 121 int count = 0;
117 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) { 122 for (const Element* sibling = element->nextElementSibling(); sibling; siblin g = sibling->nextElementSibling()) {
118 if (sibling->hasTagName(type)) 123 if (sibling->hasTagName(type))
119 ++count; 124 ++count;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 if (siblings[i] && siblings[i]->isElementNode() && siblings[i]->hasTagNa me(type)) 269 if (siblings[i] && siblings[i]->isElementNode() && siblings[i]->hasTagNa me(type))
265 return ++count; 270 return ++count;
266 } 271 }
267 272
268 return count; 273 return count;
269 } 274 }
270 275
271 } 276 }
272 277
273 #endif 278 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698