Chromium Code Reviews| Index: Source/core/dom/ContainerNode.cpp |
| diff --git a/Source/core/dom/ContainerNode.cpp b/Source/core/dom/ContainerNode.cpp |
| index 71aaabaefc7a916f48eb9d6fcbe36fbf272feeab..ca96280b2cc3ff972cbc452c8706773c37fe2872 100644 |
| --- a/Source/core/dom/ContainerNode.cpp |
| +++ b/Source/core/dom/ContainerNode.cpp |
| @@ -177,7 +177,17 @@ bool ContainerNode::checkAcceptChildGuaranteedNodeTypes(const Node& newChild, Ex |
| return true; |
| } |
| -void ContainerNode::insertBefore(PassRefPtrWillBeRawPtr<Node> newChild, Node* refChild, ExceptionState& exceptionState) |
| +Node* ContainerNode::sameNode(Node* node) |
|
Jens Widell
2014/07/10 09:14:54
I don't see why this is necessary, and performance
kangil_
2014/07/11 02:09:26
Done.
|
| +{ |
| + for (Node* child = firstChild(); child; child = child->nextSibling()) { |
| + if (child->isSameNode(node)) { |
| + return child; |
| + } |
| + } |
| + return nullptr; |
| +} |
| + |
| +PassRefPtrWillBeRawPtr<Node> ContainerNode::insertBefore(PassRefPtrWillBeRawPtr<Node> newChild, Node* refChild, ExceptionState& exceptionState) |
|
haraken
2014/07/10 09:16:02
insertBefore is in hot call paths. Calling sameNod
kangil_
2014/07/11 02:09:26
Done.
|
| { |
| #if !ENABLE(OILPAN) |
| // Check that this node is not "floating". |
| @@ -190,35 +200,36 @@ void ContainerNode::insertBefore(PassRefPtrWillBeRawPtr<Node> newChild, Node* re |
| // insertBefore(node, 0) is equivalent to appendChild(node) |
| if (!refChild) { |
| appendChild(newChild, exceptionState); |
|
Jens Widell
2014/07/10 09:18:27
We could deal with appendChild(), replaceChild() a
kangil_
2014/07/11 02:09:26
insertBefore() and appendChild() implementations a
|
| - return; |
| + return lastChild(); |
|
Jens Widell
2014/07/10 09:14:54
You should just return 'newChild' everywhere (or n
kangil_
2014/07/11 02:09:26
Done.
|
| } |
| // Make sure adding the new child is OK. |
| if (!checkAcceptChild(newChild.get(), 0, exceptionState)) |
| - return; |
| + return nullptr; |
| ASSERT(newChild); |
| // NotFoundError: Raised if refChild is not a child of this node |
| if (refChild->parentNode() != this) { |
| exceptionState.throwDOMException(NotFoundError, "The node before which the new node is to be inserted is not a child of this node."); |
| - return; |
| + return nullptr; |
| } |
| - if (refChild->previousSibling() == newChild || refChild == newChild) // nothing to do |
| - return; |
| + // nothing to do |
| + if (refChild->previousSibling() == newChild || refChild == newChild) |
| + return sameNode(newChild.get()); |
| RefPtrWillBeRawPtr<Node> next = refChild; |
| NodeVector targets; |
| collectChildrenAndRemoveFromOldParent(*newChild, targets, exceptionState); |
| if (exceptionState.hadException()) |
| - return; |
| + return nullptr; |
| if (targets.isEmpty()) |
| - return; |
| + return sameNode(newChild.get()); |
| // We need this extra check because collectChildrenAndRemoveFromOldParent() can fire mutation events. |
| if (!checkAcceptChildGuaranteedNodeTypes(*newChild, exceptionState)) |
| - return; |
| + return nullptr; |
| InspectorInstrumentation::willInsertDOMNode(this); |
| @@ -244,6 +255,8 @@ void ContainerNode::insertBefore(PassRefPtrWillBeRawPtr<Node> newChild, Node* re |
| } |
| dispatchSubtreeModifiedEvent(); |
| + |
| + return sameNode(newChild.get()); |
| } |
| void ContainerNode::insertBeforeCommon(Node& nextChild, Node& newChild) |