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

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: Rebase Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/dom/Range.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/NodeTraversal.cpp
diff --git a/Source/core/dom/NodeTraversal.cpp b/Source/core/dom/NodeTraversal.cpp
index 0f4a9f16a088c5522ada0984c9f3606287d37b00..6ad5ecd96a8c712acd2478448815781e75589ea9 100644
--- a/Source/core/dom/NodeTraversal.cpp
+++ b/Source/core/dom/NodeTraversal.cpp
@@ -110,8 +110,8 @@ Node* NodeTraversal::previous(const Node& current, const Node* stayWithin)
return 0;
if (current.previousSibling()) {
Node* previous = current.previousSibling();
- while (previous->lastChild())
- previous = previous->lastChild();
+ while (Node* child = previous->lastChild())
+ previous = child;
return previous;
}
return current.parentNode();
@@ -139,8 +139,8 @@ Node* NodeTraversal::nextPostOrder(const Node& current, const Node* stayWithin)
if (!current.nextSibling())
return current.parentNode();
Node* next = current.nextSibling();
- while (next->firstChild())
- next = next->firstChild();
+ while (Node* child = next->firstChild())
+ next = child;
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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698