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

Unified Diff: Source/platform/graphics/GraphicsLayer.cpp

Issue 187603011: GraphicsLayer::removeAllChildren shouldn't be n^2 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/graphics/GraphicsLayer.cpp
diff --git a/Source/platform/graphics/GraphicsLayer.cpp b/Source/platform/graphics/GraphicsLayer.cpp
index e1c27e2ccb2fdd091b507240a7d300c1c5220fa7..eaeb476e208a2095f487688aeba1a207459a17c1 100644
--- a/Source/platform/graphics/GraphicsLayer.cpp
+++ b/Source/platform/graphics/GraphicsLayer.cpp
@@ -278,8 +278,8 @@ bool GraphicsLayer::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChil
void GraphicsLayer::removeAllChildren()
{
- while (m_children.size()) {
- GraphicsLayer* curLayer = m_children[0];
+ while (!m_children.isEmpty()) {
+ GraphicsLayer* curLayer = m_children.last();
ASSERT(curLayer->parent());
curLayer->removeFromParent();
}
@@ -288,14 +288,8 @@ void GraphicsLayer::removeAllChildren()
void GraphicsLayer::removeFromParent()
{
if (m_parent) {
- unsigned i;
- for (i = 0; i < m_parent->m_children.size(); i++) {
- if (this == m_parent->m_children[i]) {
- m_parent->m_children.remove(i);
- break;
- }
- }
-
+ // We use reverseFind so that removeAllChildren() isn't n^2.
+ m_parent->m_children.remove(m_parent->m_children.reverseFind(this));
setParent(0);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698