Bug 145935

Summary: Fix minor ES6 compliance issue in RegExp.prototype.toString and optimize performance a little
Product: WebKit Reporter: Darin Adler <darin>
Component: JavaScriptCoreAssignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, benjamin, fpizlo, ggaren, ljharb, msaboff, sam
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch andersca: review+

Description Darin Adler 2015-06-12 12:11:59 PDT
Fix minor ES6 compliance issue in RegExp.prototype.toString and optimize performance a little
Comment 1 Darin Adler 2015-06-12 12:12:54 PDT
My first cut at a patch doesn’t have a regression test because I don’t know where to put it.
Comment 2 Darin Adler 2015-06-12 12:15:08 PDT
Created attachment 254813 [details]
Patch
Comment 3 Darin Adler 2015-06-12 12:15:48 PDT
Comment on attachment 254813 [details]
Patch

Don’t really want to get this reviewed until I add a test for the behavior change.
Comment 4 Jordan Harband 2015-06-12 12:16:19 PDT
LGTM, thanks for cleaning up my patch too!
Comment 5 Darin Adler 2015-06-12 12:17:48 PDT
Created attachment 254814 [details]
Patch
Comment 6 Darin Adler 2015-06-12 18:12:30 PDT
Created attachment 254844 [details]
Patch
Comment 7 Darin Adler 2015-06-12 18:13:26 PDT
Now this has a test. Added a few people who might review the patch.
Comment 8 Anders Carlsson 2015-06-12 18:23:36 PDT
Comment on attachment 254844 [details]
Patch

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

> Source/JavaScriptCore/runtime/RegExpPrototype.cpp:140
> +typedef char FlagsString[3 + 1]; // 3 different flags and a null character terminator

I'd use std::array for this.

> Source/JavaScriptCore/runtime/RegExpPrototype.cpp:142
> +static inline void getFlags(ExecState* exec, JSObject* regexp, FlagsString& flags)

I don't think this needs to use the get pattern - it can just return a FlagsString (if FlagsString were an std::array that is).

> Source/JavaScriptCore/runtime/RegExpPrototype.cpp:159
> +    flags[index] = 0;

I'd assert that index < sizeof(FlagsString) here.
Comment 9 Anders Carlsson 2015-06-12 18:26:24 PDT
(In reply to comment #8)

> > Source/JavaScriptCore/runtime/RegExpPrototype.cpp:142
> > +static inline void getFlags(ExecState* exec, JSObject* regexp, FlagsString& flags)
> 
> I don't think this needs to use the get pattern - it can just return a
> FlagsString (if FlagsString were an std::array that is).
> 

I just tested, and if a function returns an std::array<char, 4>, the compiler will just put the entire value in a register - no memory access needed!
Comment 10 Darin Adler 2015-06-12 18:35:44 PDT
Committed r185528: <http://trac.webkit.org/changeset/185528>
Comment 11 Anders Carlsson 2015-06-12 18:38:48 PDT
(In reply to comment #10)
> Committed r185528: <http://trac.webkit.org/changeset/185528>

I think you need to initialize std::array (You can use std::fill for example).
Comment 12 Darin Adler 2015-06-12 18:42:55 PDT
(In reply to comment #11)
> (In reply to comment #10)
> > Committed r185528: <http://trac.webkit.org/changeset/185528>
> 
> I think you need to initialize std::array (You can use std::fill for
> example).

I don’t think I do.

If there is an exception, the return value is ignored.

If the array is used, we initialize the characters in the string and the null character terminator. We don't need to initialize the rest of the array.

Might need to initialize it if we use some strict memory debugger tool or validator perhaps.