jsSubstring() should be lazy
https://bugs.webkit.org/show_bug.cgi?id=132556

Reviewed by Andreas Kling.
        

Source/JavaScriptCore: 
jsSubstring() is now lazy by using a special rope that is a substring instead of a
concatenation. To make this patch super simple, we require that a substring's base is
never a rope. Hence, when resolving a rope, we either go down a non-recursive substring
path, or we go down a concatenation path which may see exactly one level of substrings in
its fibers.
        
This is up to a 50% speed-up on microbenchmarks and a 10% speed-up on Octane/regexp.

* heap/MarkedBlock.cpp:
(JSC::MarkedBlock::specializedSweep):
* runtime/JSString.cpp:
(JSC::JSRopeString::visitFibers):
(JSC::JSRopeString::resolveRope):
(JSC::JSRopeString::resolveRopeSlowCase8):
(JSC::JSRopeString::resolveRopeSlowCase):
(JSC::JSRopeString::outOfMemory):
* runtime/JSString.h:
(JSC::JSRopeString::finishCreation):
(JSC::JSRopeString::append):
(JSC::JSRopeString::create):
(JSC::JSRopeString::offsetOfFibers):
(JSC::JSRopeString::fiber):
(JSC::JSRopeString::substringBase):
(JSC::JSRopeString::substringOffset):
(JSC::JSRopeString::substringSentinel):
(JSC::JSRopeString::isSubstring):
(JSC::jsSubstring):
* runtime/RegExpMatchesArray.cpp:
(JSC::RegExpMatchesArray::reifyAllProperties):
* runtime/StringPrototype.cpp:
(JSC::stringProtoFuncSubstring):

LayoutTests: 
These tests get 35-50% faster.

* js/regress/script-tests/substring-concat-weird.js: Added.
(foo):
* js/regress/script-tests/substring-concat.js: Added.
(foo):
* js/regress/script-tests/substring.js: Added.
(foo):
* js/regress/substring-concat-expected.txt: Added.
* js/regress/substring-concat-weird-expected.txt: Added.
* js/regress/substring-concat-weird.html: Added.
* js/regress/substring-concat.html: Added.
* js/regress/substring-expected.txt: Added.
* js/regress/substring.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@168254 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Unreviewed, rolling out r168254.

Very crashy on debug JSC tests.

Reverted changeset:

"jsSubstring() should be lazy"
https://bugs.webkit.org/show_bug.cgi?id=132556
http://trac.webkit.org/changeset/168254

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@168255 268f45cc-cd09-0410-ab3c-d52691b4dbfc
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: http://svn.webkit.org/repository/webkit/trunk@168256 268f45cc-cd09-0410-ab3c-d52691b4dbfc