Title: [176030] trunk/Source/WebCore
Revision
176030
Author
[email protected]
Date
2014-11-12 12:07:54 -0800 (Wed, 12 Nov 2014)

Log Message

Speed up HTMLTextFormControlElement::setInnerTextValue() a bit
https://bugs.webkit.org/show_bug.cgi?id=138619

Reviewed by Darin Adler.

Speed up HTMLTextFormControlElement::setInnerTextValue() a bit by:
- Not doing a virtual isTextFormControl() call. Relying on innerTextElement()
  not returning null is sufficient.
- Caching the result of innerTextElement() instead of repeatedly calling that
  virtual function.
- De-virtualizing setFormControlValueMatchesRenderer() /
  formControlValueMatchesRenderer() as these are never overridden.
- Moving the code constructing the innerTextValue from a
  TextControlInnerTextElement from innerTextValue() to a new
  innerTextValueFrom(TextControlInnerTextElement&) function and call this new
  function from setInnerTextValue() to avoid calling innerTextElement() again
  and making sure it is non-null
- Do the tree traversal from innerTextElement's firstChild instead of from
  innerTextElement. The innerTextElement is a TextControlInnerTextElement.
  Therefore, it cannot be an HTMLBRElement or a Text node.

No new tests, no behavior change.

* html/HTMLFormControlElement.h:
(WebCore::HTMLFormControlElement::formControlValueMatchesRenderer):
(WebCore::HTMLFormControlElement::setFormControlValueMatchesRenderer):
* html/HTMLTextFormControlElement.cpp:
(WebCore::stripTrailingNewline):
(WebCore::innerTextValueFrom):
(WebCore::HTMLTextFormControlElement::setInnerTextValue):
(WebCore::HTMLTextFormControlElement::innerTextValue):
(WebCore::HTMLTextFormControlElement::valueWithHardLineBreaks):
(WebCore::finishText): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (176029 => 176030)


--- trunk/Source/WebCore/ChangeLog	2014-11-12 19:34:45 UTC (rev 176029)
+++ trunk/Source/WebCore/ChangeLog	2014-11-12 20:07:54 UTC (rev 176030)
@@ -1,3 +1,39 @@
+2014-11-12  Chris Dumez  <[email protected]>
+
+        Speed up HTMLTextFormControlElement::setInnerTextValue() a bit
+        https://bugs.webkit.org/show_bug.cgi?id=138619
+
+        Reviewed by Darin Adler.
+
+        Speed up HTMLTextFormControlElement::setInnerTextValue() a bit by:
+        - Not doing a virtual isTextFormControl() call. Relying on innerTextElement()
+          not returning null is sufficient.
+        - Caching the result of innerTextElement() instead of repeatedly calling that
+          virtual function.
+        - De-virtualizing setFormControlValueMatchesRenderer() /
+          formControlValueMatchesRenderer() as these are never overridden.
+        - Moving the code constructing the innerTextValue from a
+          TextControlInnerTextElement from innerTextValue() to a new
+          innerTextValueFrom(TextControlInnerTextElement&) function and call this new
+          function from setInnerTextValue() to avoid calling innerTextElement() again
+          and making sure it is non-null
+        - Do the tree traversal from innerTextElement's firstChild instead of from
+          innerTextElement. The innerTextElement is a TextControlInnerTextElement.
+          Therefore, it cannot be an HTMLBRElement or a Text node.
+
+        No new tests, no behavior change.
+
+        * html/HTMLFormControlElement.h:
+        (WebCore::HTMLFormControlElement::formControlValueMatchesRenderer):
+        (WebCore::HTMLFormControlElement::setFormControlValueMatchesRenderer):
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::stripTrailingNewline):
+        (WebCore::innerTextValueFrom):
+        (WebCore::HTMLTextFormControlElement::setInnerTextValue):
+        (WebCore::HTMLTextFormControlElement::innerTextValue):
+        (WebCore::HTMLTextFormControlElement::valueWithHardLineBreaks):
+        (WebCore::finishText): Deleted.
+
 2014-11-12  Jer Noble  <[email protected]>
 
         [Mac] media/track/audio-track.html is flakey

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (176029 => 176030)


--- trunk/Source/WebCore/html/HTMLFormControlElement.h	2014-11-12 19:34:45 UTC (rev 176029)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h	2014-11-12 20:07:54 UTC (rev 176030)
@@ -58,8 +58,8 @@
 
     virtual void reset() { }
 
-    virtual bool formControlValueMatchesRenderer() const { return m_valueMatchesRenderer; }
-    virtual void setFormControlValueMatchesRenderer(bool b) { m_valueMatchesRenderer = b; }
+    bool formControlValueMatchesRenderer() const { return m_valueMatchesRenderer; }
+    void setFormControlValueMatchesRenderer(bool b) { m_valueMatchesRenderer = b; }
 
     bool wasChangedSinceLastFormControlChangeEvent() const { return m_wasChangedSinceLastFormControlChangeEvent; }
     void setChangedSinceLastFormControlChangeEvent(bool);

Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp (176029 => 176030)


--- trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2014-11-12 19:34:45 UTC (rev 176029)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2014-11-12 20:07:54 UTC (rev 176030)
@@ -521,52 +521,53 @@
     return m_lastChangeWasUserEdit;
 }
 
+static void stripTrailingNewline(StringBuilder& result)
+{
+    // Remove one trailing newline; there's always one that's collapsed out by rendering.
+    size_t size = result.length();
+    if (size && result[size - 1] == newlineCharacter)
+        result.resize(size - 1);
+}
+
+static String innerTextValueFrom(TextControlInnerTextElement& innerText)
+{
+    StringBuilder result;
+    for (Node* node = innerText.firstChild(); node; node = NodeTraversal::next(node, &innerText)) {
+        if (is<HTMLBRElement>(*node))
+            result.append(newlineCharacter);
+        else if (is<Text>(*node))
+            result.append(downcast<Text>(*node).data());
+    }
+    stripTrailingNewline(result);
+    return result.toString();
+}
+
 void HTMLTextFormControlElement::setInnerTextValue(const String& value)
 {
-    if (!isTextFormControl())
+    TextControlInnerTextElement* innerText = innerTextElement();
+    if (!innerText)
         return;
 
-    bool textIsChanged = value != innerTextValue();
-    if (textIsChanged || !innerTextElement()->hasChildNodes()) {
+    ASSERT(isTextFormControl());
+    bool textIsChanged = value != innerTextValueFrom(*innerText);
+    if (textIsChanged || !innerText->hasChildNodes()) {
         if (textIsChanged && renderer()) {
             if (AXObjectCache* cache = document().existingAXObjectCache())
                 cache->postNotification(this, AXObjectCache::AXValueChanged, TargetObservableParent);
         }
-        innerTextElement()->setInnerText(value, ASSERT_NO_EXCEPTION);
+        innerText->setInnerText(value, ASSERT_NO_EXCEPTION);
 
         if (value.endsWith('\n') || value.endsWith('\r'))
-            innerTextElement()->appendChild(HTMLBRElement::create(document()), ASSERT_NO_EXCEPTION);
+            innerText->appendChild(HTMLBRElement::create(document()), ASSERT_NO_EXCEPTION);
     }
 
     setFormControlValueMatchesRenderer(true);
 }
 
-static String finishText(StringBuilder& result)
-{
-    // Remove one trailing newline; there's always one that's collapsed out by rendering.
-    size_t size = result.length();
-    if (size && result[size - 1] == newlineCharacter)
-        result.resize(--size);
-    return result.toString();
-}
-
 String HTMLTextFormControlElement::innerTextValue() const
 {
-    if (!isTextFormControl())
-        return emptyString();
-
     TextControlInnerTextElement* innerText = innerTextElement();
-    if (!innerText)
-        return emptyString();
-
-    StringBuilder result;
-    for (Node* node = innerText; node; node = NodeTraversal::next(node, innerText)) {
-        if (is<HTMLBRElement>(*node))
-            result.append(newlineCharacter);
-        else if (is<Text>(*node))
-            result.append(downcast<Text>(*node).data());
-    }
-    return finishText(result);
+    return innerText ? innerTextValueFrom(*innerText) : emptyString();
 }
 
 static Position positionForIndex(TextControlInnerTextElement* innerText, unsigned index)
@@ -704,7 +705,8 @@
         while (breakNode == node)
             getNextSoftBreak(line, breakNode, breakOffset);
     }
-    return finishText(result);
+    stripTrailingNewline(result);
+    return result.toString();
 }
 
 HTMLTextFormControlElement* enclosingTextFormControl(const Position& position)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to