Bug 145427

Summary: jsSubstring() should support creating substrings from substrings.
Product: WebKit Reporter: Andreas Kling <kling>
Component: JavaScriptCoreAssignee: Andreas Kling <kling>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, ggaren, kling
Priority: P2 Keywords: Performance
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
darin: review+
Patch ggaren: review+

Description Andreas Kling 2015-05-27 21:13:33 PDT
It would be neat if jsSubstring() would be smarter when asked to create a substring of a JSString that is itself a substring.
It should share the base string and just modify the offset instead.
Comment 1 Andreas Kling 2015-05-27 21:30:27 PDT
Created attachment 253831 [details]
Patch
Comment 2 Geoffrey Garen 2015-05-28 10:18:05 PDT
Comment on attachment 253831 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253831&action=review

Yo dawg.

> Source/JavaScriptCore/runtime/JSString.h:532
> +    if (s->isRope() && !static_cast<JSRopeString*>(s)->isSubstring())
> +        static_cast<JSRopeString*>(s)->resolveRope(exec);

Can we move this branch into the callee?

It feels unsafe that the callee assumes it will not be passed a non-substring rope, when nothing in its type signature guarantees it.
Comment 3 Darin Adler 2015-05-28 13:04:19 PDT
Comment on attachment 253831 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253831&action=review

> Source/JavaScriptCore/runtime/JSString.h:304
> +            JSRopeString* baseRope = static_cast<JSRopeString*>(base);

I suggest we use a reference rather than pointer here.

>> Source/JavaScriptCore/runtime/JSString.h:532
>> +        static_cast<JSRopeString*>(s)->resolveRope(exec);
> 
> Can we move this branch into the callee?
> 
> It feels unsafe that the callee assumes it will not be passed a non-substring rope, when nothing in its type signature guarantees it.

I agree that would be better.
Comment 4 Andreas Kling 2015-06-09 21:46:22 PDT
Created attachment 254629 [details]
Patch

Take 2, rope resolution moved to callee as requested by reviewers.
Comment 5 Geoffrey Garen 2015-06-10 14:24:53 PDT
Comment on attachment 254629 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=254629&action=review

r=me

> Source/JavaScriptCore/runtime/JSString.h:314
> +        // For now, let's not allow substrings with a rope base.
> +        // Resolve non-substring rope bases so we don't have to deal with it.

Might be nice to elaborate on what we're trying to avoid.

> Source/JavaScriptCore/runtime/JSString.h:315
> +        if (base.isRope() && !base.isSubstring())

Is it possible for our base to be a substring? I think it is not, since all substrings will do the base forwarding above upon creation.
Comment 6 Andreas Kling 2015-06-23 18:18:48 PDT
Landed in r185486