Changeset 278404 in webkit
- Timestamp:
- Jun 3, 2021, 6:10:38 AM (5 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 1 added
- 6 edited
-
ChangeLog (modified) (1 diff)
-
WTF.xcodeproj/project.pbxproj (modified) (2 diffs)
-
wtf/CMakeLists.txt (modified) (1 diff)
-
wtf/text/StringBuilder.cpp (modified) (4 diffs)
-
wtf/text/StringBuilder.h (modified) (1 diff)
-
wtf/text/StringBuilderInternals.h (added)
-
wtf/text/StringBuilderJSON.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r278384 r278404 1 2021-06-03 Michael Catanzaro <mcatanzaro@gnome.org> 2 3 REGRESSION(r277744): Broke build on s390x mainframes 4 https://bugs.webkit.org/show_bug.cgi?id=226497 5 6 Reviewed by Darin Adler. 7 8 The problem is we have a template defined in a C++ source file, used by multiple source 9 files. This is not valid C++, so let's split the templates defined in StringBuilder.cpp out 10 into a new StringBuilderInternals.h that we can #include in both StringBuilder.cpp and 11 StringBuilderJSON.cpp. 12 13 Ideally we would move the template defined in StringBuilderJSON.cpp as well, and then 14 eliminate StringBuilderJSON.cpp since there would only be one function left. But that file 15 has an MPL license. It's easier to leave it be to keep the license situation simpler. 16 17 * WTF.xcodeproj/project.pbxproj: 18 * wtf/CMakeLists.txt: 19 * wtf/text/StringBuilder.cpp: 20 (WTF::StringBuilder::expandedCapacity): 21 (WTF::expandedCapacity): Deleted. 22 (WTF::StringBuilder::allocateBuffer): Deleted. 23 (WTF::StringBuilder::extendBufferForAppending): Deleted. 24 (WTF::StringBuilder::extendBufferForAppendingSlowCase): Deleted. 25 * wtf/text/StringBuilder.h: 26 * wtf/text/StringBuilderInternals.h: Added. 27 (WTF::StringBuilder::allocateBuffer): 28 (WTF::StringBuilder::reallocateBuffer): 29 (WTF::StringBuilder::extendBufferForAppending): 30 (WTF::StringBuilder::extendBufferForAppendingSlowCase): 31 * wtf/text/StringBuilderJSON.cpp: 32 1 33 2021-06-02 Chris Dumez <cdumez@apple.com> 2 34 -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r278344 r278404 655 655 A8A47324151A825B004123FF /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = "<group>"; }; 656 656 A8A47325151A825B004123FF /* StringBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringBuilder.h; sourceTree = "<group>"; }; 657 A8A47325151A825B004123EE /* StringBuilderInternals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringBuilderInternals.h; sourceTree = "<group>"; }; 657 658 A8A47326151A825B004123FF /* StringConcatenate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringConcatenate.h; sourceTree = "<group>"; }; 658 659 A8A47327151A825B004123FF /* StringHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringHash.h; sourceTree = "<group>"; }; … … 1425 1426 A8A47324151A825B004123FF /* StringBuilder.cpp */, 1426 1427 A8A47325151A825B004123FF /* StringBuilder.h */, 1428 A8A47325151A825B004123EE /* StringBuilderInternals.h */, 1427 1429 E38D6E261F5522E300A75CC4 /* StringBuilderJSON.cpp */, 1428 1430 430B47871AAAAC1A001223DA /* StringCommon.h */, -
trunk/Source/WTF/wtf/CMakeLists.txt
r278355 r278404 347 347 text/StringBuffer.h 348 348 text/StringBuilder.h 349 text/StringBuilderInternals.h 349 350 text/StringCommon.h 350 351 text/StringConcatenate.h -
trunk/Source/WTF/wtf/text/StringBuilder.cpp
r277744 r278404 29 29 30 30 #include <wtf/dtoa.h> 31 #include <wtf/text/StringBuilderInternals.h> 31 32 32 33 namespace WTF { … … 34 35 static constexpr unsigned maxCapacity = String::MaxLength; 35 36 36 static unsignedexpandedCapacity(unsigned capacity, unsigned requiredCapacity)37 unsigned StringBuilder::expandedCapacity(unsigned capacity, unsigned requiredCapacity) 37 38 { 38 39 static constexpr unsigned minimumCapacity = 16; … … 103 104 } 104 105 105 // Allocate a new buffer, copying in currentCharacters (these may come from either m_string or m_buffer.106 template<typename AllocationCharacterType, typename CurrentCharacterType> void StringBuilder::allocateBuffer(const CurrentCharacterType* currentCharacters, unsigned requiredCapacity)107 {108 AllocationCharacterType* bufferCharacters;109 auto buffer = StringImpl::tryCreateUninitialized(requiredCapacity, bufferCharacters);110 if (UNLIKELY(!buffer)) {111 didOverflow();112 return;113 }114 115 ASSERT(!hasOverflowed());116 StringImpl::copyCharacters(bufferCharacters, currentCharacters, m_length);117 118 m_buffer = WTFMove(buffer);119 m_string = { };120 }121 122 template<typename CharacterType> void StringBuilder::reallocateBuffer(unsigned requiredCapacity)123 {124 // If the buffer has only one ref (by this StringBuilder), reallocate it.125 if (m_buffer) {126 m_string = { }; // Clear the string to remove the reference to m_buffer if any before checking the reference count of m_buffer.127 if (m_buffer->hasOneRef()) {128 CharacterType* bufferCharacters;129 auto buffer = StringImpl::tryReallocate(m_buffer.releaseNonNull(), requiredCapacity, bufferCharacters);130 if (UNLIKELY(!buffer)) {131 didOverflow();132 return;133 }134 m_buffer = WTFMove(*buffer);135 return;136 }137 }138 139 allocateBuffer<CharacterType>(characters<CharacterType>(), requiredCapacity);140 }141 142 106 void StringBuilder::reallocateBuffer(unsigned requiredCapacity) 143 107 { … … 167 131 } 168 132 ASSERT(hasOverflowed() || !newCapacity || m_buffer->length() >= newCapacity); 169 }170 171 // Make 'additionalLength' additional capacity be available in m_buffer, update m_string & m_length to use,172 // that capacity and return a pointer to the newly allocated storage so the caller can write characters there.173 // Returns nullptr if allocation fails, length overflows, or if total capacity is 0 so no buffer is needed.174 // The caller has the responsibility for checking that CharacterType is the type of the existing buffer.175 template<typename CharacterType> CharacterType* StringBuilder::extendBufferForAppending(unsigned requiredLength)176 {177 if (m_buffer && requiredLength <= m_buffer->length()) {178 m_string = { };179 return const_cast<CharacterType*>(m_buffer->characters<CharacterType>()) + std::exchange(m_length, requiredLength);180 }181 return extendBufferForAppendingSlowCase<CharacterType>(requiredLength);182 }183 184 // Shared by the other extendBuffer functions.185 template<typename CharacterType> CharacterType* StringBuilder::extendBufferForAppendingSlowCase(unsigned requiredLength)186 {187 ASSERT(!hasOverflowed());188 if (!requiredLength)189 return nullptr;190 reallocateBuffer(expandedCapacity(capacity(), requiredLength));191 if (UNLIKELY(hasOverflowed()))192 return nullptr;193 return const_cast<CharacterType*>(m_buffer->characters<CharacterType>()) + std::exchange(m_length, requiredLength);194 133 } 195 134 -
trunk/Source/WTF/wtf/text/StringBuilder.h
r277967 r278404 104 104 105 105 private: 106 static unsigned expandedCapacity(unsigned capacity, unsigned requiredCapacity); 107 106 108 template<typename AllocationCharacterType, typename CurrentCharacterType> void allocateBuffer(const CurrentCharacterType* currentCharacters, unsigned requiredCapacity); 107 109 template<typename CharacterType> void reallocateBuffer(unsigned requiredCapacity); -
trunk/Source/WTF/wtf/text/StringBuilderJSON.cpp
r278338 r278404 13 13 #include <wtf/text/StringBuilder.h> 14 14 15 #include <wtf/text/StringBuilderInternals.h> 15 16 #include <wtf/text/WTFString.h> 16 17
Note:
See TracChangeset
for help on using the changeset viewer.