Changeset 249015 in webkit
- Timestamp:
- Aug 22, 2019 9:50:27 AM (5 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r249013 r249015 1 2019-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 1 18 2019-08-17 Darin Adler <darin@apple.com> 2 19 -
trunk/Source/WTF/wtf/text/StringBuilder.cpp
r248913 r249015 114 114 if (UNLIKELY(!buffer)) 115 115 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()); 117 117 118 118 // Update the builder state. … … 132 132 if (UNLIKELY(!buffer)) 133 133 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. 135 135 136 136 // Update the builder state. … … 234 234 // return a pointer to the newly allocated storage. 235 235 // Returns nullptr if the size of the new builder would have overflowed 236 template<typename CharacterType> ALWAYS_INLINE CharacterType* StringBuilder:: appendUninitialized(unsigned additionalLength)236 template<typename CharacterType> ALWAYS_INLINE CharacterType* StringBuilder::extendBufferForAppending(unsigned additionalLength) 237 237 { 238 238 ASSERT(additionalLength); … … 245 245 } 246 246 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 250 template<typename CharacterType> ALWAYS_INLINE CharacterType* StringBuilder::extendBufferForAppendingWithoutOverflowCheck(CheckedInt32 requiredLength) 251 251 { 252 252 ASSERT(!requiredLength.hasOverflowed()); … … 261 261 } 262 262 263 return appendUninitializedSlow<CharacterType>(requiredLength.unsafeGet());264 } 265 266 LChar* StringBuilder:: appendUninitialized8(CheckedInt32 requiredLength)263 return extendBufferForAppendingSlowCase<CharacterType>(requiredLength.unsafeGet()); 264 } 265 266 LChar* StringBuilder::extendBufferForAppending8(CheckedInt32 requiredLength) 267 267 { 268 268 if (UNLIKELY(requiredLength.hasOverflowed())) { … … 270 270 return nullptr; 271 271 } 272 return appendUninitializedWithoutOverflowCheck<LChar>(requiredLength);273 } 274 275 UChar* StringBuilder:: appendUninitialized16(CheckedInt32 requiredLength)272 return extendBufferForAppendingWithoutOverflowCheck<LChar>(requiredLength); 273 } 274 275 UChar* StringBuilder::extendBufferForAppending16(CheckedInt32 requiredLength) 276 276 { 277 277 if (UNLIKELY(requiredLength.hasOverflowed())) { … … 295 295 return m_bufferCharacters16 + oldLength; 296 296 } 297 return appendUninitializedWithoutOverflowCheck<UChar>(requiredLength);297 return extendBufferForAppendingWithoutOverflowCheck<UChar>(requiredLength); 298 298 } 299 299 300 300 // Make 'requiredLength' capacity be available in m_buffer, update m_string & m_length, 301 301 // return a pointer to the newly allocated storage. 302 template<typename CharacterType> CharacterType* StringBuilder:: appendUninitializedSlow(unsigned requiredLength)302 template<typename CharacterType> CharacterType* StringBuilder::extendBufferForAppendingSlowCase(unsigned requiredLength) 303 303 { 304 304 ASSERT(!hasOverflowed()); … … 338 338 // FIXME: Should we optimize memory by keeping the string 8-bit when all the characters are Latin-1? 339 339 340 UChar* destination = appendUninitialized16(m_length + length);340 UChar* destination = extendBufferForAppending16(m_length + length); 341 341 if (UNLIKELY(!destination)) 342 342 return; … … 354 354 355 355 if (m_is8Bit) { 356 LChar* dest = appendUninitialized<LChar>(length);357 if (!dest ) {356 LChar* destination = extendBufferForAppending<LChar>(length); 357 if (!destination) { 358 358 ASSERT(hasOverflowed()); 359 359 return; 360 360 } 361 361 if (length > 8) 362 memcpy(dest, characters, length);362 std::memcpy(destination, characters, length); 363 363 else { 364 364 // FIXME: How strong is our evidence that this is faster than memcpy? What platforms is this true for? 365 365 const LChar* end = characters + length; 366 366 while (characters < end) 367 * (dest++) = *(characters++);367 *destination++ = *characters++; 368 368 } 369 369 } else { 370 UChar* dest = appendUninitialized<UChar>(length);371 if (!dest ) {370 UChar* destination = extendBufferForAppending<UChar>(length); 371 if (!destination) { 372 372 ASSERT(hasOverflowed()); 373 373 return; … … 375 375 const LChar* end = characters + length; 376 376 while (characters < end) 377 * (dest++) = *(characters++);377 *destination++ = *characters++; 378 378 } 379 379 } -
trunk/Source/WTF/wtf/text/StringBuilder.h
r248903 r249015 358 358 void allocateBufferUpConvert(const LChar* currentCharacters, unsigned requiredLength); 359 359 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); 365 365 366 366 template<typename CharacterType> ALWAYS_INLINE CharacterType* getBufferCharacters(); … … 402 402 auto requiredLength = checkedSum<int32_t>(m_length, adapters.length()...); 403 403 if (m_is8Bit && are8Bit(adapters...)) { 404 LChar* destination = appendUninitialized8(requiredLength);404 LChar* destination = extendBufferForAppending8(requiredLength); 405 405 if (!destination) { 406 406 ASSERT(hasOverflowed()); … … 409 409 stringTypeAdapterAccumulator(destination, adapters...); 410 410 } else { 411 UChar* destination = appendUninitialized16(requiredLength);411 UChar* destination = extendBufferForAppending16(requiredLength); 412 412 if (!destination) { 413 413 ASSERT(hasOverflowed());
Note: See TracChangeset
for help on using the changeset viewer.