Changeset 133726 in webkit


Ignore:
Timestamp:
Nov 6, 2012, 11:13:20 PM (13 years ago)
Author:
msaboff@apple.com
Message:

StringBuilder::append(UChar) with an 8 bit quantity shouldn't change the contents to 16 bits
https://bugs.webkit.org/show_bug.cgi?id=101421

Reviewed by Anders Carlsson.

If the string builder contains only 8 bit data, check if the character being appended contains
8 bit data. If so, append it to the 8 bit buffer instead of converting the buffer to 16 bits.

  • wtf/text/StringBuilder.cpp:

(WTF::StringBuilder::append):

  • wtf/text/StringBuilder.h:

(WTF::StringBuilder::append):

Location:
trunk/Source/WTF
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r133653 r133726  
     12012-11-06  Michael Saboff  <msaboff@apple.com>
     2
     3        StringBuilder::append(UChar) with an 8 bit quantity shouldn't change the contents to 16 bits
     4        https://bugs.webkit.org/show_bug.cgi?id=101421
     5
     6        Reviewed by Anders Carlsson.
     7
     8        If the string builder contains only 8 bit data, check if the character being appended contains
     9        8 bit data.  If so, append it to the 8 bit buffer instead of converting the buffer to 16 bits.
     10
     11        * wtf/text/StringBuilder.cpp:
     12        (WTF::StringBuilder::append):
     13        * wtf/text/StringBuilder.h:
     14        (WTF::StringBuilder::append):
     15
    1162012-11-06  Benjamin Poulain  <benjamin@webkit.org>
    217
  • trunk/Source/WTF/wtf/text/StringBuilder.cpp

    r128014 r133726  
    244244
    245245    if (m_is8Bit) {
     246        if (length == 1 && !(*characters & ~0xff)) {
     247            // Append as 8 bit character
     248            LChar lChar = static_cast<LChar>(*characters);
     249            append(&lChar, 1);
     250            return;
     251        }
     252
    246253        // Calculate the new size of the builder after appending.
    247254        unsigned requiredLength = length + m_length;
  • trunk/Source/WTF/wtf/text/StringBuilder.h

    r131250 r133726  
    112112    void append(UChar c)
    113113    {
    114         if (m_buffer && !m_is8Bit && m_length < m_buffer->length() && m_string.isNull())
    115             m_bufferCharacters16[m_length++] = c;
    116         else
    117             append(&c, 1);
     114        if (m_buffer && m_length < m_buffer->length() && m_string.isNull()) {
     115            if (!m_is8Bit) {
     116                m_bufferCharacters16[m_length++] = c;
     117                return;
     118            }
     119
     120            if (!(c & ~0xff)) {
     121                m_bufferCharacters8[m_length++] = static_cast<LChar>(c);
     122                return;
     123            }
     124        }
     125        append(&c, 1);
    118126    }
    119127
Note: See TracChangeset for help on using the changeset viewer.