Changeset 249015 in webkit


Ignore:
Timestamp:
Aug 22, 2019 9:50:27 AM (5 years ago)
Author:
Darin Adler
Message:

Rename StringBuilder functions to avoid unclear "append uninitialized" terminology
https://bugs.webkit.org/show_bug.cgi?id=201020

Reviewed by Alex Christensen.

  • wtf/text/StringBuilder.cpp:

(WTF::StringBuilder::allocateBuffer): Use std::memcpy instead of just memcpy.
(WTF::StringBuilder::extendBufferForAppending): Renamed.
(WTF::StringBuilder::extendBufferForAppendingWithoutOverflowCheck): Ditto.
(WTF::StringBuilder::extendBufferForAppending8): Ditto.
(WTF::StringBuilder::extendBufferForAppending16): Ditto.
(WTF::StringBuilder::extendBufferForAppendingSlowPath): Ditto.
(WTF::StringBuilder::appendCharacters): Updated for new names.

  • wtf/text/StringBuilder.h: Updated for new names.
Location:
trunk/Source/WTF
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r249013 r249015  
     12019-08-22  Darin Adler  <darin@apple.com>
     2
     3        Rename StringBuilder functions to avoid unclear "append uninitialized" terminology
     4        https://bugs.webkit.org/show_bug.cgi?id=201020
     5
     6        Reviewed by Alex Christensen.
     7
     8        * wtf/text/StringBuilder.cpp:
     9        (WTF::StringBuilder::allocateBuffer): Use std::memcpy instead of just memcpy.
     10        (WTF::StringBuilder::extendBufferForAppending): Renamed.
     11        (WTF::StringBuilder::extendBufferForAppendingWithoutOverflowCheck): Ditto.
     12        (WTF::StringBuilder::extendBufferForAppending8): Ditto.
     13        (WTF::StringBuilder::extendBufferForAppending16): Ditto.
     14        (WTF::StringBuilder::extendBufferForAppendingSlowPath): Ditto.
     15        (WTF::StringBuilder::appendCharacters): Updated for new names.
     16        * wtf/text/StringBuilder.h: Updated for new names.
     17
    1182019-08-17  Darin Adler  <darin@apple.com>
    219
  • trunk/Source/WTF/wtf/text/StringBuilder.cpp

    r248913 r249015  
    114114    if (UNLIKELY(!buffer))
    115115        return didOverflow();
    116     memcpy(m_bufferCharacters8, currentCharacters, static_cast<size_t>(m_length.unsafeGet()) * sizeof(LChar)); // This can't overflow.
     116    std::memcpy(m_bufferCharacters8, currentCharacters, m_length.unsafeGet());
    117117   
    118118    // Update the builder state.
     
    132132    if (UNLIKELY(!buffer))
    133133        return didOverflow();
    134     memcpy(m_bufferCharacters16, currentCharacters, static_cast<size_t>(m_length.unsafeGet()) * sizeof(UChar)); // This can't overflow.
     134    std::memcpy(m_bufferCharacters16, currentCharacters, static_cast<size_t>(m_length.unsafeGet()) * sizeof(UChar)); // This can't overflow.
    135135   
    136136    // Update the builder state.
     
    234234// return a pointer to the newly allocated storage.
    235235// Returns nullptr if the size of the new builder would have overflowed
    236 template<typename CharacterType> ALWAYS_INLINE CharacterType* StringBuilder::appendUninitialized(unsigned additionalLength)
     236template<typename CharacterType> ALWAYS_INLINE CharacterType* StringBuilder::extendBufferForAppending(unsigned additionalLength)
    237237{
    238238    ASSERT(additionalLength);
     
    245245    }
    246246
    247     return appendUninitializedWithoutOverflowCheck<CharacterType>(requiredLength);
    248 }
    249 
    250 template<typename CharacterType> ALWAYS_INLINE CharacterType* StringBuilder::appendUninitializedWithoutOverflowCheck(CheckedInt32 requiredLength)
     247    return extendBufferForAppendingWithoutOverflowCheck<CharacterType>(requiredLength);
     248}
     249
     250template<typename CharacterType> ALWAYS_INLINE CharacterType* StringBuilder::extendBufferForAppendingWithoutOverflowCheck(CheckedInt32 requiredLength)
    251251{
    252252    ASSERT(!requiredLength.hasOverflowed());
     
    261261    }
    262262
    263     return appendUninitializedSlow<CharacterType>(requiredLength.unsafeGet());
    264 }
    265 
    266 LChar* StringBuilder::appendUninitialized8(CheckedInt32 requiredLength)
     263    return extendBufferForAppendingSlowCase<CharacterType>(requiredLength.unsafeGet());
     264}
     265
     266LChar* StringBuilder::extendBufferForAppending8(CheckedInt32 requiredLength)
    267267{
    268268    if (UNLIKELY(requiredLength.hasOverflowed())) {
     
    270270        return nullptr;
    271271    }
    272     return appendUninitializedWithoutOverflowCheck<LChar>(requiredLength);
    273 }
    274 
    275 UChar* StringBuilder::appendUninitialized16(CheckedInt32 requiredLength)
     272    return extendBufferForAppendingWithoutOverflowCheck<LChar>(requiredLength);
     273}
     274
     275UChar* StringBuilder::extendBufferForAppending16(CheckedInt32 requiredLength)
    276276{
    277277    if (UNLIKELY(requiredLength.hasOverflowed())) {
     
    295295        return m_bufferCharacters16 + oldLength;
    296296    }
    297     return appendUninitializedWithoutOverflowCheck<UChar>(requiredLength);
     297    return extendBufferForAppendingWithoutOverflowCheck<UChar>(requiredLength);
    298298}
    299299
    300300// Make 'requiredLength' capacity be available in m_buffer, update m_string & m_length,
    301301// return a pointer to the newly allocated storage.
    302 template<typename CharacterType> CharacterType* StringBuilder::appendUninitializedSlow(unsigned requiredLength)
     302template<typename CharacterType> CharacterType* StringBuilder::extendBufferForAppendingSlowCase(unsigned requiredLength)
    303303{
    304304    ASSERT(!hasOverflowed());
     
    338338    // FIXME: Should we optimize memory by keeping the string 8-bit when all the characters are Latin-1?
    339339
    340     UChar* destination = appendUninitialized16(m_length + length);
     340    UChar* destination = extendBufferForAppending16(m_length + length);
    341341    if (UNLIKELY(!destination))
    342342        return;
     
    354354
    355355    if (m_is8Bit) {
    356         LChar* dest = appendUninitialized<LChar>(length);
    357         if (!dest) {
     356        LChar* destination = extendBufferForAppending<LChar>(length);
     357        if (!destination) {
    358358            ASSERT(hasOverflowed());
    359359            return;
    360360        }
    361361        if (length > 8)
    362             memcpy(dest, characters, length);
     362            std::memcpy(destination, characters, length);
    363363        else {
    364364            // FIXME: How strong is our evidence that this is faster than memcpy? What platforms is this true for?
    365365            const LChar* end = characters + length;
    366366            while (characters < end)
    367                 *(dest++) = *(characters++);
     367                *destination++ = *characters++;
    368368        }
    369369    } else {
    370         UChar* dest = appendUninitialized<UChar>(length);
    371         if (!dest) {
     370        UChar* destination = extendBufferForAppending<UChar>(length);
     371        if (!destination) {
    372372            ASSERT(hasOverflowed());
    373373            return;
     
    375375        const LChar* end = characters + length;
    376376        while (characters < end)
    377             *(dest++) = *(characters++);
     377            *destination++ = *characters++;
    378378    }
    379379}
  • trunk/Source/WTF/wtf/text/StringBuilder.h

    r248903 r249015  
    358358    void allocateBufferUpConvert(const LChar* currentCharacters, unsigned requiredLength);
    359359    template<typename CharacterType> void reallocateBuffer(unsigned requiredLength);
    360     template<typename CharacterType> ALWAYS_INLINE CharacterType* appendUninitialized(unsigned additionalLength);
    361     template<typename CharacterType> ALWAYS_INLINE CharacterType* appendUninitializedWithoutOverflowCheck(CheckedInt32 requiredLength);
    362     template<typename CharacterType> CharacterType* appendUninitializedSlow(unsigned requiredLength);
    363     WTF_EXPORT_PRIVATE LChar* appendUninitialized8(CheckedInt32 requiredLength);
    364     WTF_EXPORT_PRIVATE UChar* appendUninitialized16(CheckedInt32 requiredLength);
     360    template<typename CharacterType> ALWAYS_INLINE CharacterType* extendBufferForAppending(unsigned additionalLength);
     361    template<typename CharacterType> ALWAYS_INLINE CharacterType* extendBufferForAppendingWithoutOverflowCheck(CheckedInt32 requiredLength);
     362    template<typename CharacterType> CharacterType* extendBufferForAppendingSlowCase(unsigned requiredLength);
     363    WTF_EXPORT_PRIVATE LChar* extendBufferForAppending8(CheckedInt32 requiredLength);
     364    WTF_EXPORT_PRIVATE UChar* extendBufferForAppending16(CheckedInt32 requiredLength);
    365365
    366366    template<typename CharacterType> ALWAYS_INLINE CharacterType* getBufferCharacters();
     
    402402    auto requiredLength = checkedSum<int32_t>(m_length, adapters.length()...);
    403403    if (m_is8Bit && are8Bit(adapters...)) {
    404         LChar* destination = appendUninitialized8(requiredLength);
     404        LChar* destination = extendBufferForAppending8(requiredLength);
    405405        if (!destination) {
    406406            ASSERT(hasOverflowed());
     
    409409        stringTypeAdapterAccumulator(destination, adapters...);
    410410    } else {
    411         UChar* destination = appendUninitialized16(requiredLength);
     411        UChar* destination = extendBufferForAppending16(requiredLength);
    412412        if (!destination) {
    413413            ASSERT(hasOverflowed());
Note: See TracChangeset for help on using the changeset viewer.