Changeset 123504 in webkit


Ignore:
Timestamp:
Jul 24, 2012, 12:12:42 PM (13 years ago)
Author:
benjamin@webkit.org
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 <bpoulain@apple.com> 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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r123500 r123504  
     12012-07-24  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Do not perform 8 to 16bits characters conversion when converting a WTFString to NSString/CFString
     4        https://bugs.webkit.org/show_bug.cgi?id=90720
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        In most String to CFString conversion, we should be able to use the "NoCopy" constructor and have
     9        a relatively cheap conversion from WTF::String to CFString.
     10
     11        When the String is 8 bits, it was converted to 16 bits by getData16SlowCase() because of the call
     12        to String::characters().
     13
     14        This patch adds a path for creating a CFString from a 8bits string using CFStringCreateWithBytes.
     15
     16        This is covered by existing tests.
     17
     18        * platform/text/cf/StringCF.cpp:
     19        (WTF::String::createCFString): CFSTR() create static CFString, it is unecessary to retain it.
     20        * platform/text/cf/StringImplCF.cpp:
     21        (WTF::StringImpl::createCFString): The logic to avoid the StringWrapperCFAllocator has also been simplified.
     22        The allocator creation is now closer to where it is useful.
     23
    1242012-07-24  Kentaro Hara  <haraken@chromium.org>
    225
  • trunk/Source/WebCore/platform/text/cf/StringCF.cpp

    r79434 r123504  
    4646{
    4747    if (!m_impl)
    48         return static_cast<CFStringRef>(CFRetain(CFSTR("")));
     48        return CFSTR("");
    4949
    5050    return m_impl->createCFString();
  • trunk/Source/WebCore/platform/text/cf/StringImplCF.cpp

    r98624 r123504  
    135135CFStringRef StringImpl::createCFString()
    136136{
    137     CFAllocatorRef allocator = (m_length && isMainThread()) ? StringWrapperCFAllocator::allocator() : 0;
    138     if (!allocator)
    139         return CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(characters()), m_length);
     137    if (!m_length || !isMainThread()) {
     138        if (is8Bit())
     139            return CFStringCreateWithBytes(0, reinterpret_cast<const UInt8*>(characters8()), m_length, kCFStringEncodingISOLatin1, false);
     140        return CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(characters16()), m_length);
     141    }
     142    CFAllocatorRef allocator = StringWrapperCFAllocator::allocator();
    140143
    141144    // Put pointer to the StringImpl in a global so the allocator can store it with the CFString.
     
    143146    StringWrapperCFAllocator::currentString = this;
    144147
    145     CFStringRef string = CFStringCreateWithCharactersNoCopy(allocator, reinterpret_cast<const UniChar*>(characters()), m_length, kCFAllocatorNull);
     148    CFStringRef string;
     149    if (is8Bit())
     150        string = CFStringCreateWithBytesNoCopy(allocator, reinterpret_cast<const UInt8*>(characters8()), m_length, kCFStringEncodingISOLatin1, false, kCFAllocatorNull);
     151    else
     152        string = CFStringCreateWithCharactersNoCopy(allocator, reinterpret_cast<const UniChar*>(characters16()), m_length, kCFAllocatorNull);
    146153
    147154    // The allocator cleared the global when it read it, but also clear it here just in case.
Note: See TracChangeset for help on using the changeset viewer.