Changeset 127392 in webkit


Ignore:
Timestamp:
Sep 2, 2012 1:26:26 PM (12 years ago)
Author:
benjamin@webkit.org
Message:

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

Patch by Benjamin Poulain <bpoulain@apple.com> 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):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r127391 r127392  
     12012-09-02  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Improve the way we use convertedSpaceString() in convertHTMLTextToInterchangeFormat()
     4        https://bugs.webkit.org/show_bug.cgi?id=95301
     5
     6        Reviewed by Darin Adler.
     7
     8        The static string convertedSpaceString() had a couple of annoying side effects:
     9        -The string was 16bits due to noBreakSpace, which forced any input to be converted to 16bits.
     10        -The string was kept in the heap for no particular reason.
     11
     12        This patch redefines convertedSpaceString as a constant literal so that we can use it efficiently.
     13
     14        The patch also make the binary a tiny bit smaller (700 bytes).
     15
     16        * editing/HTMLInterchange.cpp:
     17        (WebCore::convertHTMLTextToInterchangeFormat):
     18
    1192012-09-02  Mike West  <mkwst@chromium.org>
    220
  • trunk/Source/WebCore/editing/HTMLInterchange.cpp

    r126984 r127392  
    3636namespace WebCore {
    3737
    38 static String convertedSpaceString()
    39 {
    40     DEFINE_STATIC_LOCAL(String, convertedSpaceString, (String(ASCIILiteral("<span class=\"" AppleConvertedSpace "\">")) + noBreakSpace + "</span>"));
    41     return convertedSpaceString;
    42 }
    43 
    4438String convertHTMLTextToInterchangeFormat(const String& in, const Text* node)
    4539{
     
    4741    if (node->renderer() && node->renderer()->style()->preserveNewline())
    4842        return in;
     43
     44    const char convertedSpaceString[] = "<span class=\"" AppleConvertedSpace "\">\xA0</span>";
     45    COMPILE_ASSERT((static_cast<unsigned char>('\xA0') == noBreakSpace), ConvertedSpaceStringSpaceIsNoBreakSpace);
    4946
    5047    StringBuilder s;
     
    6562                switch (add) {
    6663                    case 0:
    67                         s.append(convertedSpaceString());
     64                        s.appendLiteral(convertedSpaceString);
    6865                        s.append(' ');
    69                         s.append(convertedSpaceString());
     66                        s.appendLiteral(convertedSpaceString);
    7067                        add = 3;
    7168                        break;
    7269                    case 1:
    7370                        if (i == 0 || i + 1 == in.length()) // at start or end of string
    74                             s.append(convertedSpaceString());
     71                            s.appendLiteral(convertedSpaceString);
    7572                        else
    7673                            s.append(' ');
     
    7976                        if (i == 0) {
    8077                             // at start of string
    81                             s.append(convertedSpaceString());
     78                            s.appendLiteral(convertedSpaceString);
    8279                            s.append(' ');
    8380                        } else if (i + 2 == in.length()) {
    8481                             // at end of string
    85                             s.append(convertedSpaceString());
    86                             s.append(convertedSpaceString());
     82                            s.appendLiteral(convertedSpaceString);
     83                            s.appendLiteral(convertedSpaceString);
    8784                        } else {
    88                             s.append(convertedSpaceString());
     85                            s.appendLiteral(convertedSpaceString);
    8986                            s.append(' ');
    9087                        }
Note: See TracChangeset for help on using the changeset viewer.