Title: [127392] trunk/Source/WebCore
Revision
127392
Author
[email protected]
Date
2012-09-02 13:26:26 -0700 (Sun, 02 Sep 2012)

Log Message

Improve the way we use convertedSpaceString() in convertHTMLTextToInterchangeFormat()
https://bugs.webkit.org/show_bug.cgi?id=95301

Patch by Benjamin Poulain <[email protected]> on 2012-09-02
Reviewed by Darin Adler.

The static string convertedSpaceString() had a couple of annoying side effects:
-The string was 16bits due to noBreakSpace, which forced any input to be converted to 16bits.
-The string was kept in the heap for no particular reason.

This patch redefines convertedSpaceString as a constant literal so that we can use it efficiently.

The patch also make the binary a tiny bit smaller (700 bytes).

* editing/HTMLInterchange.cpp:
(WebCore::convertHTMLTextToInterchangeFormat):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (127391 => 127392)


--- trunk/Source/WebCore/ChangeLog	2012-09-02 18:57:20 UTC (rev 127391)
+++ trunk/Source/WebCore/ChangeLog	2012-09-02 20:26:26 UTC (rev 127392)
@@ -1,3 +1,21 @@
+2012-09-02  Benjamin Poulain  <[email protected]>
+
+        Improve the way we use convertedSpaceString() in convertHTMLTextToInterchangeFormat()
+        https://bugs.webkit.org/show_bug.cgi?id=95301
+
+        Reviewed by Darin Adler.
+
+        The static string convertedSpaceString() had a couple of annoying side effects:
+        -The string was 16bits due to noBreakSpace, which forced any input to be converted to 16bits.
+        -The string was kept in the heap for no particular reason.
+
+        This patch redefines convertedSpaceString as a constant literal so that we can use it efficiently.
+
+        The patch also make the binary a tiny bit smaller (700 bytes).
+
+        * editing/HTMLInterchange.cpp:
+        (WebCore::convertHTMLTextToInterchangeFormat):
+
 2012-09-02  Mike West  <[email protected]>
 
         Build is broken when SVG is disabled.

Modified: trunk/Source/WebCore/editing/HTMLInterchange.cpp (127391 => 127392)


--- trunk/Source/WebCore/editing/HTMLInterchange.cpp	2012-09-02 18:57:20 UTC (rev 127391)
+++ trunk/Source/WebCore/editing/HTMLInterchange.cpp	2012-09-02 20:26:26 UTC (rev 127392)
@@ -35,18 +35,15 @@
 
 namespace WebCore {
 
-static String convertedSpaceString()
-{
-    DEFINE_STATIC_LOCAL(String, convertedSpaceString, (String(ASCIILiteral("<span class=\"" AppleConvertedSpace "\">")) + noBreakSpace + "</span>"));
-    return convertedSpaceString;
-}
-
 String convertHTMLTextToInterchangeFormat(const String& in, const Text* node)
 {
     // Assume all the text comes from node.
     if (node->renderer() && node->renderer()->style()->preserveNewline())
         return in;
 
+    const char convertedSpaceString[] = "<span class=\"" AppleConvertedSpace "\">\xA0</span>";
+    COMPILE_ASSERT((static_cast<unsigned char>('\xA0') == noBreakSpace), ConvertedSpaceStringSpaceIsNoBreakSpace);
+
     StringBuilder s;
 
     unsigned i = 0;
@@ -64,28 +61,28 @@
                 unsigned add = count % 3;
                 switch (add) {
                     case 0:
-                        s.append(convertedSpaceString());
+                        s.appendLiteral(convertedSpaceString);
                         s.append(' ');
-                        s.append(convertedSpaceString());
+                        s.appendLiteral(convertedSpaceString);
                         add = 3;
                         break;
                     case 1:
                         if (i == 0 || i + 1 == in.length()) // at start or end of string
-                            s.append(convertedSpaceString());
+                            s.appendLiteral(convertedSpaceString);
                         else
                             s.append(' ');
                         break;
                     case 2:
                         if (i == 0) {
                              // at start of string
-                            s.append(convertedSpaceString());
+                            s.appendLiteral(convertedSpaceString);
                             s.append(' ');
                         } else if (i + 2 == in.length()) {
                              // at end of string
-                            s.append(convertedSpaceString());
-                            s.append(convertedSpaceString());
+                            s.appendLiteral(convertedSpaceString);
+                            s.appendLiteral(convertedSpaceString);
                         } else {
-                            s.append(convertedSpaceString());
+                            s.appendLiteral(convertedSpaceString);
                             s.append(' ');
                         }
                         break;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to