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

Unified Diff: Source/core/dom/NodeTraversal.cpp

Issue 307243004: Avoid calling slower Node::firstChild() / Node::lastChild() when possible (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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
Index: Source/core/dom/NodeTraversal.cpp
diff --git a/Source/core/dom/NodeTraversal.cpp b/Source/core/dom/NodeTraversal.cpp
index 0f4a9f16a088c5522ada0984c9f3606287d37b00..a4fe5dd9ed7d0c5d56ede20e6a61cb4b493d9536 100644
--- a/Source/core/dom/NodeTraversal.cpp
+++ b/Source/core/dom/NodeTraversal.cpp
@@ -111,7 +111,7 @@ Node* NodeTraversal::previous(const Node& current, const Node* stayWithin)
if (current.previousSibling()) {
Node* previous = current.previousSibling();
while (previous->lastChild())
esprehn 2014/06/02 19:03:37 This is silly, don't call it twice. while (Node*
Inactive 2014/06/02 20:46:25 Done.
- previous = previous->lastChild();
+ previous = toContainerNode(previous)->lastChild();
return previous;
}
return current.parentNode();
@@ -140,7 +140,7 @@ Node* NodeTraversal::nextPostOrder(const Node& current, const Node* stayWithin)
return current.parentNode();
Node* next = current.nextSibling();
while (next->firstChild())
- next = next->firstChild();
+ next = toContainerNode(next)->firstChild();
esprehn 2014/06/02 19:03:37 dito.
Inactive 2014/06/02 20:46:25 Done.
return next;
}
@@ -158,8 +158,8 @@ static Node* previousAncestorSiblingPostOrder(const Node& current, const Node* s
Node* NodeTraversal::previousPostOrder(const Node& current, const Node* stayWithin)
{
- if (current.lastChild())
- return current.lastChild();
+ if (Node* lastChild = current.lastChild())
+ return lastChild;
if (current == stayWithin)
return 0;
if (current.previousSibling())
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/dom/Range.cpp » ('j') | Source/core/dom/Range.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698