Add JSStringCreateWithCharactersNoCopy SPI
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jun 2013 23:23:26 +0000 (23:23 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jun 2013 23:23:26 +0000 (23:23 +0000)
commit633e1c4a3f33d6354749a50922d6ddc5ece36fb6
treea43982ba2415e9a1a700abd9494815cbe9d671f6
parentc99e72167fafd9c99af2defdc4c626a12f9fee08
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.

* JavaScriptCore.xcodeproj/project.pbxproj:
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@152052 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/JavaScriptCore/API/JSStringRef.cpp
Source/JavaScriptCore/API/JSStringRefPrivate.h [new file with mode: 0644]
Source/JavaScriptCore/API/OpaqueJSString.h
Source/JavaScriptCore/API/tests/testapi.c
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/WTF/ChangeLog
Source/WTF/wtf/text/StringImpl.cpp
Source/WTF/wtf/text/StringImpl.h