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); |
} |