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

Unified Diff: Source/core/dom/Node.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 | « LayoutTests/fast/repaint/set-text-content-same-expected.txt ('k') | Source/core/editing/markup.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Node.cpp
diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp
index fd21496a66b511e2e28694d47baf1f617357b67b..3ba014c5338b9dc8f89abe1f880cadb78b19867b 100644
--- a/Source/core/dom/Node.cpp
+++ b/Source/core/dom/Node.cpp
@@ -59,6 +59,7 @@
#include "core/dom/shadow/InsertionPoint.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/editing/htmlediting.h"
+#include "core/editing/markup.h"
#include "core/events/BeforeLoadEvent.h"
#include "core/events/Event.h"
#include "core/events/EventDispatchMediator.h"
@@ -1496,9 +1497,15 @@ void Node::setTextContent(const String& text)
case ELEMENT_NODE:
case ATTRIBUTE_NODE:
case DOCUMENT_FRAGMENT_NODE: {
+ // FIXME: Merge this logic into replaceChildrenWithText.
RefPtr<ContainerNode> container = toContainerNode(this);
+ // No need to do anything if the text is identical.
+ if (container->hasOneTextChild() && toText(container->firstChild())->data() == text)
+ return;
ChildListMutationScope mutation(*this);
container->removeChildren();
+ // Note: This API will not insert empty text nodes:
+ // http://dom.spec.whatwg.org/#dom-node-textcontent
if (!text.isEmpty())
container->appendChild(document().createTextNode(text), ASSERT_NO_EXCEPTION);
return;
« no previous file with comments | « LayoutTests/fast/repaint/set-text-content-same-expected.txt ('k') | Source/core/editing/markup.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698