Changeset 152289 in webkit


Ignore:
Timestamp:
Jul 2, 2013 6:36:09 AM (11 years ago)
Author:
mikhail.pozdnyakov@intel.com
Message:

Avoid code duplication inside String::append()
https://bugs.webkit.org/show_bug.cgi?id=118290

Reviewed by Anders Carlsson.

The implementation of 'append(UChar)' had been repeated inside 'append(LChar)',
this duplication is obviated now.

  • wtf/text/WTFString.cpp:

(WTF::String::appendInternal):
(WTF::String::append):

  • wtf/text/WTFString.h:
Location:
trunk/Source/WTF
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r152201 r152289  
     12013-07-02  Mikhail Pozdnyakov  <mikhail.pozdnyakov@intel.com>
     2
     3        Avoid code duplication inside String::append()
     4        https://bugs.webkit.org/show_bug.cgi?id=118290
     5
     6        Reviewed by Anders Carlsson.
     7
     8        The implementation of 'append(UChar)' had been repeated inside 'append(LChar)',
     9        this duplication is obviated now.
     10
     11        * wtf/text/WTFString.cpp:
     12        (WTF::String::appendInternal):
     13        (WTF::String::append):
     14        * wtf/text/WTFString.h:
     15
    1162013-06-28  Anders Carlsson  <andersca@apple.com>
    217
  • trunk/Source/WTF/wtf/text/WTFString.cpp

    r152201 r152289  
    120120}
    121121
    122 void String::append(LChar c)
     122template <typename CharacterType>
     123inline void String::appendInternal(CharacterType c)
    123124{
    124125    // FIXME: This is extremely inefficient. So much so that we might want to take this
     
    138139}
    139140
     141void String::append(LChar c)
     142{
     143    appendInternal(c);
     144}
     145
    140146void String::append(UChar c)
    141147{
    142     // FIXME: This is extremely inefficient. So much so that we might want to take this
    143     // out of String's API. We can make it better by optimizing the case where exactly
    144     // one String is pointing at this StringImpl, but even then it's going to require a
    145     // call to fastMalloc every single time.
    146     if (m_impl) {
    147         UChar* data;
    148         if (m_impl->length() >= numeric_limits<unsigned>::max())
    149             CRASH();
    150         RefPtr<StringImpl> newImpl = StringImpl::createUninitialized(m_impl->length() + 1, data);
    151         memcpy(data, m_impl->characters(), m_impl->length() * sizeof(UChar));
    152         data[m_impl->length()] = c;
    153         m_impl = newImpl.release();
    154     } else
    155         m_impl = StringImpl::create(&c, 1);
     148    appendInternal(c);
    156149}
    157150
  • trunk/Source/WTF/wtf/text/WTFString.h

    r152201 r152289  
    495495    template <typename CharacterType>
    496496    void removeInternal(const CharacterType*, unsigned, int);
     497
     498    template <typename CharacterType>
     499    void appendInternal(CharacterType);
    497500
    498501    RefPtr<StringImpl> m_impl;
Note: See TracChangeset for help on using the changeset viewer.