Changeset 272752 in webkit
- Timestamp:
- Feb 11, 2021, 2:24:00 PM (6 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
wtf/text/WTFString.h (modified) (1 diff)
-
wtf/text/cf/StringCF.cpp (modified) (2 diffs)
-
wtf/text/cocoa/StringCocoa.mm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r272736 r272752 1 2021-02-11 Alex Christensen <achristensen@webkit.org> 2 3 Reduce string copies when converting from NSString/CFStringRef to WTF::String 4 https://bugs.webkit.org/show_bug.cgi?id=221766 5 6 Reviewed by Geoff Garen. 7 8 This reduces the string copies from two to one which should speed up many things. 9 The cost is that for non-Latin1-encodable strings of length less than 1024, we now do an allocation 10 and a reallocation, whereas before we were doing just one allocation. I think even in this case, though, 11 the cost of a reallocation should be comparable to the cost of doing a double string copy, 12 and the benefit of reducing a string copy everywhere is compelling. 13 14 I also reduced duplicate code by combining the CF and NS implementations. 15 16 * wtf/text/WTFString.h: 17 * wtf/text/cf/StringCF.cpp: 18 (WTF::String::String): 19 * wtf/text/cocoa/StringCocoa.mm: 20 (WTF::String::String): Deleted. 21 1 22 2021-02-11 Sam Weinig <weinig@apple.com> 2 23 -
trunk/Source/WTF/wtf/text/WTFString.h
r271633 r272752 320 320 321 321 #ifdef __OBJC__ 322 WTF_EXPORT_PRIVATE String(NSString *); 322 String(NSString *string) 323 : String((__bridge CFStringRef)string) { } 323 324 324 325 // This conversion converts the null string to an empty NSString rather than to nil. -
trunk/Source/WTF/wtf/text/cf/StringCF.cpp
r165676 r272752 26 26 #include <CoreFoundation/CoreFoundation.h> 27 27 #include <wtf/RetainPtr.h> 28 #include <wtf/text/StringBuffer.h> 28 29 29 30 namespace WTF { … … 35 36 36 37 CFIndex size = CFStringGetLength(str); 37 if ( size == 0)38 if (!size) { 38 39 m_impl = StringImpl::empty(); 39 else { 40 Vector<LChar, 1024> lcharBuffer(size); 40 return; 41 } 42 43 { 44 StringBuffer<LChar> buffer(size); 41 45 CFIndex usedBufLen; 42 CFIndex converted size = CFStringGetBytes(str, CFRangeMake(0, size), kCFStringEncodingISOLatin1, 0, false, lcharBuffer.data(), size, &usedBufLen);43 if ( (convertedsize == size) && (usedBufLen == size)) {44 m_impl = StringImpl:: create(lcharBuffer.data(), size);46 CFIndex convertedSize = CFStringGetBytes(str, CFRangeMake(0, size), kCFStringEncodingISOLatin1, 0, false, buffer.characters(), size, &usedBufLen); 47 if (convertedSize == size && usedBufLen == size) { 48 m_impl = StringImpl::adopt(WTFMove(buffer)); 45 49 return; 46 50 } 51 } 47 52 48 Vector<UChar, 1024> buffer(size); 49 CFStringGetCharacters(str, CFRangeMake(0, size), (UniChar*)buffer.data()); 50 m_impl = StringImpl::create(buffer.data(), size); 51 } 53 StringBuffer<UChar> ucharBuffer(size); 54 CFStringGetCharacters(str, CFRangeMake(0, size), reinterpret_cast<UniChar *>(ucharBuffer.characters())); 55 m_impl = StringImpl::adopt(WTFMove(ucharBuffer)); 52 56 } 53 57 -
trunk/Source/WTF/wtf/text/cocoa/StringCocoa.mm
r262814 r272752 26 26 namespace WTF { 27 27 28 String::String(NSString *str)29 {30 if (!str)31 return;32 33 CFIndex size = CFStringGetLength((__bridge CFStringRef)str);34 if (!size)35 m_impl = StringImpl::empty();36 else {37 Vector<LChar, 1024> lcharBuffer(size);38 CFIndex usedBufLen;39 CFIndex convertedsize = CFStringGetBytes((__bridge CFStringRef)str, CFRangeMake(0, size), kCFStringEncodingISOLatin1, 0, false, lcharBuffer.data(), size, &usedBufLen);40 if ((convertedsize == size) && (usedBufLen == size)) {41 m_impl = StringImpl::create(lcharBuffer.data(), size);42 return;43 }44 45 Vector<UChar, 1024> ucharBuffer(size);46 CFStringGetCharacters((__bridge CFStringRef)str, CFRangeMake(0, size), reinterpret_cast<UniChar*>(ucharBuffer.data()));47 m_impl = StringImpl::create(ucharBuffer.data(), size);48 }49 }50 51 28 RetainPtr<id> makeNSArrayElement(const String& vectorElement) 52 29 {
Note:
See TracChangeset
for help on using the changeset viewer.