Bug 145427 - jsSubstring() should support creating substrings from substrings.
Summary: jsSubstring() should support creating substrings from substrings.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andreas Kling
URL:
Keywords: Performance
Depends on:
Blocks:
 
Reported: 2015-05-27 21:13 PDT by Andreas Kling
Modified: 2015-06-23 18:18 PDT (History)
3 users (show)

See Also:


Attachments
Patch (2.81 KB, patch)
2015-05-27 21:30 PDT, Andreas Kling
darin: review+
Details | Formatted Diff | Diff
Patch (4.49 KB, patch)
2015-06-09 21:46 PDT, Andreas Kling
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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