Optimize JSRopeString for resolving directly to AtomicString.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 May 2014 06:24:44 +0000 (06:24 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 May 2014 06:24:44 +0000 (06:24 +0000)
commit494e50845efecc29165304dabf8580425b384e7e
tree2de69149d6c8dab27c13d6e2a7883960c74ce5c4
parentf244e8b88af4c273a975ee6eeee5d2187d7a9b5b
Optimize JSRopeString for resolving directly to AtomicString.
<https://webkit.org/b/132548>

Source/JavaScriptCore:
If we know that the JSRopeString we are resolving is going to be used
as an AtomicString, we can try to avoid creating a new string.

We do this by first resolving the rope into a stack buffer, and using
that buffer as a key into the AtomicString table. If there is already
an AtomicString with the same characters, we reuse that instead of
constructing a new StringImpl.

JSString gains these two public functions:

- AtomicString toAtomicString()

    Returns an AtomicString, tries to avoid allocating a new string
    if possible.

- AtomicStringImpl* toExistingAtomicString()

    Returns a non-null AtomicStringImpl* if one already exists in the
    AtomicString table. If none is found, the rope is left unresolved.

Reviewed by Filip Pizlo.

* runtime/JSString.cpp:
(JSC::JSRopeString::resolveRopeInternal8):
(JSC::JSRopeString::resolveRopeInternal16):
(JSC::JSRopeString::resolveRopeToAtomicString):
(JSC::JSRopeString::clearFibers):
(JSC::JSRopeString::resolveRopeToExistingAtomicString):
(JSC::JSRopeString::resolveRope):
(JSC::JSRopeString::outOfMemory):
* runtime/JSString.h:
(JSC::JSString::toAtomicString):
(JSC::JSString::toExistingAtomicString):

Source/WebCore:
Add two bindings generator attributes for parameters to influence
the way that JS rope strings are resolved:

- AtomicString

    Generates code that avoids allocating a new StringImpl if there
    is already an existing AtomicString we can reuse.

- RequiresExistingAtomicString

    Generates code that fails immediately if the provided string
    is not found in the AtomicString table. This is now used for
    document.getElementById(), and works because any existing ID
    is guaranteed to be in the table.

Reviewed by Filip Pizlo.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateParametersCheck):
(JSValueToNative):
* bindings/scripts/IDLAttributes.txt:
* dom/Document.idl:

Source/WTF:
Add AtomicString::find([LU]Char*, unsigned length) helpers for finding
an existing AtomicString without a StringImpl on hand.

Reviewed by Filip Pizlo.

* wtf/text/AtomicString.h:
* wtf/text/AtomicString.cpp:
(WTF::AtomicString::find):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@168256 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSString.cpp
Source/JavaScriptCore/runtime/JSString.h
Source/WTF/ChangeLog
Source/WTF/wtf/text/AtomicString.cpp
Source/WTF/wtf/text/AtomicString.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/IDLAttributes.txt
Source/WebCore/dom/Document.idl