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

Unified Diff: Source/core/editing/markup.cpp

Issue 200763006: Node::setTextContent should avoid work when nothing changes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated beforeload-set-text-crash to not timeout Created 6 years, 9 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') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/markup.cpp
diff --git a/Source/core/editing/markup.cpp b/Source/core/editing/markup.cpp
index f7240ebcdd02b76de91fe266e63a858ff9c5b6e0..992f9ba5688b23f84e36997ae0cb426f3da247fb 100644
--- a/Source/core/editing/markup.cpp
+++ b/Source/core/editing/markup.cpp
@@ -1006,11 +1006,13 @@ void replaceChildrenWithFragment(ContainerNode* container, PassRefPtr<DocumentFr
return;
}
+ // FIXME: This is wrong if containerNode->firstChild() has more than one ref!
if (containerNode->hasOneTextChild() && fragment->hasOneTextChild()) {
toText(containerNode->firstChild())->setData(toText(fragment->firstChild())->data());
return;
}
+ // FIXME: No need to replace the child it is a text node and its contents are already == text.
if (containerNode->hasOneChild()) {
containerNode->replaceChild(fragment, containerNode->firstChild(), exceptionState);
return;
@@ -1027,13 +1029,25 @@ void replaceChildrenWithText(ContainerNode* container, const String& text, Excep
ChildListMutationScope mutation(*containerNode);
+ // FIXME: This is wrong if containerNode->firstChild() has more than one ref! Example:
+ // <div>foo</div>
+ // <script>
+ // var oldText = div.firstChild;
+ // console.log(oldText.data); // foo
+ // div.innerText = "bar";
+ // console.log(oldText.data); // bar!?!
+ // </script>
+ // I believe this is an intentional benchmark cheat from years ago.
+ // We should re-visit if we actually want this still.
if (containerNode->hasOneTextChild()) {
toText(containerNode->firstChild())->setData(text);
return;
}
+ // NOTE: This method currently always creates a text node, even if that text node will be empty.
RefPtr<Text> textNode = Text::create(containerNode->document(), text);
+ // FIXME: No need to replace the child it is a text node and its contents are already == text.
if (containerNode->hasOneChild()) {
containerNode->replaceChild(textNode.release(), containerNode->firstChild(), exceptionState);
return;
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698