Title: [173754] trunk/Source/WebCore
Revision
173754
Author
cdu...@apple.com
Date
2014-09-19 08:48:36 -0700 (Fri, 19 Sep 2014)

Log Message

Optimize MarkupAccumulator::appendText()
https://bugs.webkit.org/show_bug.cgi?id=136935

Reviewed by Benjamin Poulain.

MarkupAccumulator::appendText() was calling the generic appendNodeValue()
method to append the text. appendNodeValue() supports any kind of Node and
thus calls the Node::nodeValue() virtual function.

Since appendText() is the only caller to appendNodeValue(), this patch
inlines the code in appendText() and makes it specific to Text Node, and
thus more efficient. The code now calls CharacterData::data() instead of
the Node::nodeValue() virtual function. This patch also updates
CharacterData::data() to return a const reference to avoid copying the
return value.

No new tests, no behavior change.

* dom/CharacterData.h:
(WebCore::CharacterData::data):
* editing/MarkupAccumulator.cpp:
(WebCore::MarkupAccumulator::appendText):
(WebCore::MarkupAccumulator::appendNodeValue): Deleted.
* editing/MarkupAccumulator.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (173753 => 173754)


--- trunk/Source/WebCore/ChangeLog	2014-09-19 15:40:04 UTC (rev 173753)
+++ trunk/Source/WebCore/ChangeLog	2014-09-19 15:48:36 UTC (rev 173754)
@@ -1,3 +1,30 @@
+2014-09-19  Chris Dumez  <cdu...@apple.com>
+
+        Optimize MarkupAccumulator::appendText()
+        https://bugs.webkit.org/show_bug.cgi?id=136935
+
+        Reviewed by Benjamin Poulain.
+
+        MarkupAccumulator::appendText() was calling the generic appendNodeValue()
+        method to append the text. appendNodeValue() supports any kind of Node and
+        thus calls the Node::nodeValue() virtual function.
+
+        Since appendText() is the only caller to appendNodeValue(), this patch
+        inlines the code in appendText() and makes it specific to Text Node, and
+        thus more efficient. The code now calls CharacterData::data() instead of
+        the Node::nodeValue() virtual function. This patch also updates
+        CharacterData::data() to return a const reference to avoid copying the
+        return value.
+
+        No new tests, no behavior change.
+
+        * dom/CharacterData.h:
+        (WebCore::CharacterData::data):
+        * editing/MarkupAccumulator.cpp:
+        (WebCore::MarkupAccumulator::appendText):
+        (WebCore::MarkupAccumulator::appendNodeValue): Deleted.
+        * editing/MarkupAccumulator.h:
+
 2014-09-18  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] Dot not allow to create delete-on-destroy GMainLoopSources

Modified: trunk/Source/WebCore/dom/CharacterData.h (173753 => 173754)


--- trunk/Source/WebCore/dom/CharacterData.h	2014-09-19 15:40:04 UTC (rev 173753)
+++ trunk/Source/WebCore/dom/CharacterData.h	2014-09-19 15:48:36 UTC (rev 173754)
@@ -30,7 +30,7 @@
 
 class CharacterData : public Node {
 public:
-    String data() const { return m_data; }
+    const String& data() const { return m_data; }
     static ptrdiff_t dataMemoryOffset() { return OBJECT_OFFSETOF(CharacterData, m_data); }
 
     WEBCORE_EXPORT void setData(const String&, ExceptionCode&);

Modified: trunk/Source/WebCore/editing/MarkupAccumulator.cpp (173753 => 173754)


--- trunk/Source/WebCore/editing/MarkupAccumulator.cpp	2014-09-19 15:40:04 UTC (rev 173753)
+++ trunk/Source/WebCore/editing/MarkupAccumulator.cpp	2014-09-19 15:48:36 UTC (rev 173754)
@@ -255,24 +255,6 @@
     result.append(quoteChar);
 }
 
-void MarkupAccumulator::appendNodeValue(StringBuilder& result, const Node& node, const Range* range, EntityMask entityMask)
-{
-    const String str = node.nodeValue();
-    unsigned length = str.length();
-    unsigned start = 0;
-
-    if (range) {
-        if (&node == range->endContainer())
-            length = range->endOffset();
-        if (&node == range->startContainer()) {
-            start = range->startOffset();
-            length -= start;
-        }
-    }
-
-    appendCharactersReplacingEntities(result, str, start, length, entityMask);
-}
-
 bool MarkupAccumulator::shouldAddNamespaceElement(const Element& element)
 {
     // Don't add namespace attribute if it is already defined for this elem.
@@ -359,7 +341,20 @@
 
 void MarkupAccumulator::appendText(StringBuilder& result, const Text& text)
 {
-    appendNodeValue(result, text, m_range, entityMaskForText(text));
+    const String& textData = text.data();
+    unsigned start = 0;
+    unsigned length = textData.length();
+
+    if (m_range) {
+        if (&text == m_range->endContainer())
+            length = m_range->endOffset();
+        if (&text == m_range->startContainer()) {
+            start = m_range->startOffset();
+            length -= start;
+        }
+    }
+
+    appendCharactersReplacingEntities(result, textData, start, length, entityMaskForText(text));
 }
 
 static void appendComment(StringBuilder& result, const String& comment)

Modified: trunk/Source/WebCore/editing/MarkupAccumulator.h (173753 => 173754)


--- trunk/Source/WebCore/editing/MarkupAccumulator.h	2014-09-19 15:40:04 UTC (rev 173753)
+++ trunk/Source/WebCore/editing/MarkupAccumulator.h	2014-09-19 15:48:36 UTC (rev 173754)
@@ -87,7 +87,6 @@
     void appendEndMarkup(StringBuilder&, const Node&);
 
     void appendAttributeValue(StringBuilder&, const String&, bool);
-    void appendNodeValue(StringBuilder&, const Node&, const Range*, EntityMask);
     void appendNamespace(StringBuilder&, const AtomicString& prefix, const AtomicString& namespaceURI, Namespaces&, bool allowEmptyDefaultNS = false);
     void appendXMLDeclaration(StringBuilder&, const Document&);
     void appendDocumentType(StringBuilder&, const DocumentType&);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to