Title: [249015] trunk/Source/WTF
Revision
249015
Author
da...@apple.com
Date
2019-08-22 09:50:27 -0700 (Thu, 22 Aug 2019)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (249014 => 249015)


--- trunk/Source/WTF/ChangeLog	2019-08-22 16:42:57 UTC (rev 249014)
+++ trunk/Source/WTF/ChangeLog	2019-08-22 16:50:27 UTC (rev 249015)
@@ -1,3 +1,20 @@
+2019-08-22  Darin Adler  <da...@apple.com>
+
+        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.
+
 2019-08-17  Darin Adler  <da...@apple.com>
 
         Use makeString and multi-argument StringBuilder::append instead of less efficient multiple appends

Modified: trunk/Source/WTF/wtf/text/StringBuilder.cpp (249014 => 249015)


--- trunk/Source/WTF/wtf/text/StringBuilder.cpp	2019-08-22 16:42:57 UTC (rev 249014)
+++ trunk/Source/WTF/wtf/text/StringBuilder.cpp	2019-08-22 16:50:27 UTC (rev 249015)
@@ -113,7 +113,7 @@
     auto buffer = StringImpl::tryCreateUninitialized(requiredLength, m_bufferCharacters8);
     if (UNLIKELY(!buffer))
         return didOverflow();
-    memcpy(m_bufferCharacters8, currentCharacters, static_cast<size_t>(m_length.unsafeGet()) * sizeof(LChar)); // This can't overflow.
+    std::memcpy(m_bufferCharacters8, currentCharacters, m_length.unsafeGet());
     
     // Update the builder state.
     m_buffer = WTFMove(buffer);
@@ -131,7 +131,7 @@
     auto buffer = StringImpl::tryCreateUninitialized(requiredLength, m_bufferCharacters16);
     if (UNLIKELY(!buffer))
         return didOverflow();
-    memcpy(m_bufferCharacters16, currentCharacters, static_cast<size_t>(m_length.unsafeGet()) * sizeof(UChar)); // This can't overflow.
+    std::memcpy(m_bufferCharacters16, currentCharacters, static_cast<size_t>(m_length.unsafeGet()) * sizeof(UChar)); // This can't overflow.
     
     // Update the builder state.
     m_buffer = WTFMove(buffer);
@@ -233,7 +233,7 @@
 // Make 'additionalLength' additional capacity be available in m_buffer, update m_string & m_length,
 // return a pointer to the newly allocated storage.
 // Returns nullptr if the size of the new builder would have overflowed
-template<typename CharacterType> ALWAYS_INLINE CharacterType* StringBuilder::appendUninitialized(unsigned additionalLength)
+template<typename CharacterType> ALWAYS_INLINE CharacterType* StringBuilder::extendBufferForAppending(unsigned additionalLength)
 {
     ASSERT(additionalLength);
 
@@ -244,10 +244,10 @@
         return nullptr;
     }
 
-    return appendUninitializedWithoutOverflowCheck<CharacterType>(requiredLength);
+    return extendBufferForAppendingWithoutOverflowCheck<CharacterType>(requiredLength);
 }
 
-template<typename CharacterType> ALWAYS_INLINE CharacterType* StringBuilder::appendUninitializedWithoutOverflowCheck(CheckedInt32 requiredLength)
+template<typename CharacterType> ALWAYS_INLINE CharacterType* StringBuilder::extendBufferForAppendingWithoutOverflowCheck(CheckedInt32 requiredLength)
 {
     ASSERT(!requiredLength.hasOverflowed());
 
@@ -260,19 +260,19 @@
         return getBufferCharacters<CharacterType>() + currentLength;
     }
 
-    return appendUninitializedSlow<CharacterType>(requiredLength.unsafeGet());
+    return extendBufferForAppendingSlowCase<CharacterType>(requiredLength.unsafeGet());
 }
 
-LChar* StringBuilder::appendUninitialized8(CheckedInt32 requiredLength)
+LChar* StringBuilder::extendBufferForAppending8(CheckedInt32 requiredLength)
 {
     if (UNLIKELY(requiredLength.hasOverflowed())) {
         didOverflow();
         return nullptr;
     }
-    return appendUninitializedWithoutOverflowCheck<LChar>(requiredLength);
+    return extendBufferForAppendingWithoutOverflowCheck<LChar>(requiredLength);
 }
 
-UChar* StringBuilder::appendUninitialized16(CheckedInt32 requiredLength)
+UChar* StringBuilder::extendBufferForAppending16(CheckedInt32 requiredLength)
 {
     if (UNLIKELY(requiredLength.hasOverflowed())) {
         didOverflow();
@@ -294,12 +294,12 @@
         m_length = requiredLength.unsafeGet();
         return m_bufferCharacters16 + oldLength;
     }
-    return appendUninitializedWithoutOverflowCheck<UChar>(requiredLength);
+    return extendBufferForAppendingWithoutOverflowCheck<UChar>(requiredLength);
 }
 
 // Make 'requiredLength' capacity be available in m_buffer, update m_string & m_length,
 // return a pointer to the newly allocated storage.
-template<typename CharacterType> CharacterType* StringBuilder::appendUninitializedSlow(unsigned requiredLength)
+template<typename CharacterType> CharacterType* StringBuilder::extendBufferForAppendingSlowCase(unsigned requiredLength)
 {
     ASSERT(!hasOverflowed());
     ASSERT(requiredLength);
@@ -337,7 +337,7 @@
 
     // FIXME: Should we optimize memory by keeping the string 8-bit when all the characters are Latin-1?
 
-    UChar* destination = appendUninitialized16(m_length + length);
+    UChar* destination = extendBufferForAppending16(m_length + length);
     if (UNLIKELY(!destination))
         return;
     std::memcpy(destination, characters, static_cast<size_t>(length) * sizeof(UChar));
@@ -353,28 +353,28 @@
     ASSERT(characters);
 
     if (m_is8Bit) {
-        LChar* dest = appendUninitialized<LChar>(length);
-        if (!dest) {
+        LChar* destination = extendBufferForAppending<LChar>(length);
+        if (!destination) {
             ASSERT(hasOverflowed());
             return;
         }
         if (length > 8)
-            memcpy(dest, characters, length);
+            std::memcpy(destination, characters, length);
         else {
             // FIXME: How strong is our evidence that this is faster than memcpy? What platforms is this true for?
             const LChar* end = characters + length;
             while (characters < end)
-                *(dest++) = *(characters++);
+                *destination++ = *characters++;
         }
     } else {
-        UChar* dest = appendUninitialized<UChar>(length);
-        if (!dest) {
+        UChar* destination = extendBufferForAppending<UChar>(length);
+        if (!destination) {
             ASSERT(hasOverflowed());
             return;
         }
         const LChar* end = characters + length;
         while (characters < end)
-            *(dest++) = *(characters++);
+            *destination++ = *characters++;
     }
 }
 

Modified: trunk/Source/WTF/wtf/text/StringBuilder.h (249014 => 249015)


--- trunk/Source/WTF/wtf/text/StringBuilder.h	2019-08-22 16:42:57 UTC (rev 249014)
+++ trunk/Source/WTF/wtf/text/StringBuilder.h	2019-08-22 16:50:27 UTC (rev 249015)
@@ -357,11 +357,11 @@
     void allocateBuffer(const UChar* currentCharacters, unsigned requiredLength);
     void allocateBufferUpConvert(const LChar* currentCharacters, unsigned requiredLength);
     template<typename CharacterType> void reallocateBuffer(unsigned requiredLength);
-    template<typename CharacterType> ALWAYS_INLINE CharacterType* appendUninitialized(unsigned additionalLength);
-    template<typename CharacterType> ALWAYS_INLINE CharacterType* appendUninitializedWithoutOverflowCheck(CheckedInt32 requiredLength);
-    template<typename CharacterType> CharacterType* appendUninitializedSlow(unsigned requiredLength);
-    WTF_EXPORT_PRIVATE LChar* appendUninitialized8(CheckedInt32 requiredLength);
-    WTF_EXPORT_PRIVATE UChar* appendUninitialized16(CheckedInt32 requiredLength);
+    template<typename CharacterType> ALWAYS_INLINE CharacterType* extendBufferForAppending(unsigned additionalLength);
+    template<typename CharacterType> ALWAYS_INLINE CharacterType* extendBufferForAppendingWithoutOverflowCheck(CheckedInt32 requiredLength);
+    template<typename CharacterType> CharacterType* extendBufferForAppendingSlowCase(unsigned requiredLength);
+    WTF_EXPORT_PRIVATE LChar* extendBufferForAppending8(CheckedInt32 requiredLength);
+    WTF_EXPORT_PRIVATE UChar* extendBufferForAppending16(CheckedInt32 requiredLength);
 
     template<typename CharacterType> ALWAYS_INLINE CharacterType* getBufferCharacters();
     WTF_EXPORT_PRIVATE void reifyString() const;
@@ -401,7 +401,7 @@
 {
     auto requiredLength = checkedSum<int32_t>(m_length, adapters.length()...);
     if (m_is8Bit && are8Bit(adapters...)) {
-        LChar* destination = appendUninitialized8(requiredLength);
+        LChar* destination = extendBufferForAppending8(requiredLength);
         if (!destination) {
             ASSERT(hasOverflowed());
             return;
@@ -408,7 +408,7 @@
         }
         stringTypeAdapterAccumulator(destination, adapters...);
     } else {
-        UChar* destination = appendUninitialized16(requiredLength);
+        UChar* destination = extendBufferForAppending16(requiredLength);
         if (!destination) {
             ASSERT(hasOverflowed());
             return;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to