Skip to content
  • andersca@apple.com's avatar
    Add JSStringCreateWithCharactersNoCopy SPI · 95f564ed
    andersca@apple.com authored
    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: http://svn.webkit.org/repository/webkit/trunk@152052 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    95f564ed