Title: [123504] trunk/Source/WebCore
- Revision
- 123504
- Author
- [email protected]
- Date
- 2012-07-24 12:12:42 -0700 (Tue, 24 Jul 2012)
Log Message
Do not perform 8 to 16bits characters conversion when converting a WTFString to NSString/CFString
https://bugs.webkit.org/show_bug.cgi?id=90720
Patch by Benjamin Poulain <[email protected]> on 2012-07-24
Reviewed by Geoffrey Garen.
In most String to CFString conversion, we should be able to use the "NoCopy" constructor and have
a relatively cheap conversion from WTF::String to CFString.
When the String is 8 bits, it was converted to 16 bits by getData16SlowCase() because of the call
to String::characters().
This patch adds a path for creating a CFString from a 8bits string using CFStringCreateWithBytes.
This is covered by existing tests.
* platform/text/cf/StringCF.cpp:
(WTF::String::createCFString): CFSTR() create static CFString, it is unecessary to retain it.
* platform/text/cf/StringImplCF.cpp:
(WTF::StringImpl::createCFString): The logic to avoid the StringWrapperCFAllocator has also been simplified.
The allocator creation is now closer to where it is useful.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (123503 => 123504)
--- trunk/Source/WebCore/ChangeLog 2012-07-24 19:03:57 UTC (rev 123503)
+++ trunk/Source/WebCore/ChangeLog 2012-07-24 19:12:42 UTC (rev 123504)
@@ -1,3 +1,26 @@
+2012-07-24 Benjamin Poulain <[email protected]>
+
+ Do not perform 8 to 16bits characters conversion when converting a WTFString to NSString/CFString
+ https://bugs.webkit.org/show_bug.cgi?id=90720
+
+ Reviewed by Geoffrey Garen.
+
+ In most String to CFString conversion, we should be able to use the "NoCopy" constructor and have
+ a relatively cheap conversion from WTF::String to CFString.
+
+ When the String is 8 bits, it was converted to 16 bits by getData16SlowCase() because of the call
+ to String::characters().
+
+ This patch adds a path for creating a CFString from a 8bits string using CFStringCreateWithBytes.
+
+ This is covered by existing tests.
+
+ * platform/text/cf/StringCF.cpp:
+ (WTF::String::createCFString): CFSTR() create static CFString, it is unecessary to retain it.
+ * platform/text/cf/StringImplCF.cpp:
+ (WTF::StringImpl::createCFString): The logic to avoid the StringWrapperCFAllocator has also been simplified.
+ The allocator creation is now closer to where it is useful.
+
2012-07-24 Kentaro Hara <[email protected]>
[V8] String wrappers should be marked Independent
Modified: trunk/Source/WebCore/platform/text/cf/StringCF.cpp (123503 => 123504)
--- trunk/Source/WebCore/platform/text/cf/StringCF.cpp 2012-07-24 19:03:57 UTC (rev 123503)
+++ trunk/Source/WebCore/platform/text/cf/StringCF.cpp 2012-07-24 19:12:42 UTC (rev 123504)
@@ -45,7 +45,7 @@
CFStringRef String::createCFString() const
{
if (!m_impl)
- return static_cast<CFStringRef>(CFRetain(CFSTR("")));
+ return CFSTR("");
return m_impl->createCFString();
}
Modified: trunk/Source/WebCore/platform/text/cf/StringImplCF.cpp (123503 => 123504)
--- trunk/Source/WebCore/platform/text/cf/StringImplCF.cpp 2012-07-24 19:03:57 UTC (rev 123503)
+++ trunk/Source/WebCore/platform/text/cf/StringImplCF.cpp 2012-07-24 19:12:42 UTC (rev 123504)
@@ -134,15 +134,22 @@
CFStringRef StringImpl::createCFString()
{
- CFAllocatorRef allocator = (m_length && isMainThread()) ? StringWrapperCFAllocator::allocator() : 0;
- if (!allocator)
- return CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(characters()), m_length);
+ if (!m_length || !isMainThread()) {
+ if (is8Bit())
+ return CFStringCreateWithBytes(0, reinterpret_cast<const UInt8*>(characters8()), m_length, kCFStringEncodingISOLatin1, false);
+ return CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(characters16()), m_length);
+ }
+ CFAllocatorRef allocator = StringWrapperCFAllocator::allocator();
// Put pointer to the StringImpl in a global so the allocator can store it with the CFString.
ASSERT(!StringWrapperCFAllocator::currentString);
StringWrapperCFAllocator::currentString = this;
- CFStringRef string = CFStringCreateWithCharactersNoCopy(allocator, reinterpret_cast<const UniChar*>(characters()), m_length, kCFAllocatorNull);
+ CFStringRef string;
+ if (is8Bit())
+ string = CFStringCreateWithBytesNoCopy(allocator, reinterpret_cast<const UInt8*>(characters8()), m_length, kCFStringEncodingISOLatin1, false, kCFAllocatorNull);
+ else
+ string = CFStringCreateWithCharactersNoCopy(allocator, reinterpret_cast<const UniChar*>(characters16()), m_length, kCFAllocatorNull);
// The allocator cleared the global when it read it, but also clear it here just in case.
ASSERT(!StringWrapperCFAllocator::currentString);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes