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

Unified Diff: Source/core/dom/Range.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/NodeTraversal.cpp ('k') | Source/core/editing/ApplyStyleCommand.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Range.cpp
diff --git a/Source/core/dom/Range.cpp b/Source/core/dom/Range.cpp
index dbf1bafa2bc1c036adff6bce4ac6874cee5bd68f..de80933a0d7c44ca9b1199373eeefd183c60eb2f 100644
--- a/Source/core/dom/Range.cpp
+++ b/Source/core/dom/Range.cpp
@@ -872,7 +872,7 @@ void Range::insertNode(PassRefPtrWillBeRawPtr<Node> prpNewNode, ExceptionState&
if (newNodeType == Node::DOCUMENT_FRAGMENT_NODE && !newNode->isShadowRoot()) {
// check each child node, not the DocumentFragment itself
numNewChildren = 0;
- for (Node* c = newNode->firstChild(); c; c = c->nextSibling()) {
+ for (Node* c = toDocumentFragment(newNode)->firstChild(); c; c = c->nextSibling()) {
if (!checkAgainst->childTypeAllowed(c->nodeType())) {
exceptionState.throwDOMException(HierarchyRequestError, "The node to be inserted contains a '" + c->nodeName() + "' node, which may not be inserted here.");
return;
@@ -925,11 +925,11 @@ void Range::insertNode(PassRefPtrWillBeRawPtr<Node> prpNewNode, ExceptionState&
if (collapsed)
m_end.setToBeforeChild(*newText);
} else {
- RefPtrWillBeRawPtr<Node> lastChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? newNode->lastChild() : newNode.get();
+ RefPtrWillBeRawPtr<Node> lastChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? toDocumentFragment(newNode)->lastChild() : newNode.get();
if (lastChild && lastChild == m_start.childBefore()) {
// The insertion will do nothing, but we need to extend the range to include
// the inserted nodes.
- Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? newNode->firstChild() : newNode.get();
+ Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? toDocumentFragment(newNode)->firstChild() : newNode.get();
ASSERT(firstChild);
m_start.setToBeforeChild(*firstChild);
return;
« no previous file with comments | « Source/core/dom/NodeTraversal.cpp ('k') | Source/core/editing/ApplyStyleCommand.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698