Ignore:
Timestamp:
Jun 26, 2013, 4:23:26 PM (12 years ago)
Author:
[email protected]
Message:

Add JSStringCreateWithCharactersNoCopy SPI
https://bugs.webkit.org/show_bug.cgi?id=118074
<rdar://problem/14279905>

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

  • API/JSStringRef.cpp:

(JSStringCreateWithCharactersNoCopy):
Create a new OpaqueJSString, using the newly added StringImpl::createWithoutCopying function.

  • API/JSStringRefPrivate.h: Added.

Add a home for the JSStringCreateWithCharactersNoCopy function.

  • API/OpaqueJSString.h:

(OpaqueJSString::OpaqueJSString):
Just call isolatedCopy on the passed in string.

  • API/tests/testapi.c:

Add an API test for JSStringCreateWithCharactersNoCopy.

Add new files.

Source/WTF:

  • wtf/text/StringImpl.cpp:

(WTF::StringImpl::createFromLiteral):
Use the new ConstructWithoutCopying constructor, passing DoesHaveTerminatingNullCharacter to it.
Change the other createFromLiteral overload to just call the first.

(WTF::StringImpl::createWithoutCopying):
Add helper functions for creating strings that shouldn't copy their underlying data.

  • wtf/text/StringImpl.h:

(WTF::StringImpl::StringImpl):
Rename the ConstructFromLiteralTag constructor enum to ConstructWithoutCopyingTag. Change the constructor
to take an enum that states whether the string has a terminating null character or not.

(WTF::StringImpl::createFromLiteral):
Call createWithoutCopying.

(WTF::StringImpl::requiresCopy):
Rename this from isASCIILiteral() and make it more generic so it can handle 16-bit strings as well.

(WTF::StringImpl::isolatedCopy):
If this string doesn't have to be copied, just create a new StringImpl object that references the current data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/OpaqueJSString.h

    r148696 r152052  
    7171
    7272    OpaqueJSString(const String& string)
     73        : m_string(string.isolatedCopy())
    7374    {
    74         // Make a copy of the source string.
    75         if (string.is8Bit())
    76             m_string = String(string.characters8(), string.length());
    77         else
    78             m_string = String(string.characters16(), string.length());
    7975    }
    8076
Note: See TracChangeset for help on using the changeset viewer.