Bug 65422 - Simplify JSFunction creation for functions written in JS
Summary: Simplify JSFunction creation for functions written in JS
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Oliver Hunt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-30 17:36 PDT by Oliver Hunt
Modified: 2011-08-02 17:41 PDT (History)
0 users

See Also:


Attachments
Patch (7.46 KB, patch)
2011-07-30 17:40 PDT, Oliver Hunt
no flags Details | Formatted Diff | Diff
Patch (7.75 KB, patch)
2011-08-02 17:18 PDT, Oliver Hunt
no flags Details | Formatted Diff | Diff
Patch (7.77 KB, patch)
2011-08-02 17:32 PDT, Oliver Hunt
barraclough: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Hunt 2011-07-30 17:36:13 PDT
Simplify JSFunction creation for functions written in JS
Comment 1 Oliver Hunt 2011-07-30 17:40:06 PDT
Created attachment 102447 [details]
Patch
Comment 2 Darin Adler 2011-07-30 19:35:35 PDT
Comment on attachment 102447 [details]
Patch

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

> Source/JavaScriptCore/runtime/Executable.cpp:147
> +    m_jsName.set(globalData, name.isEmpty() ? globalData.smallStrings.emptyString(&globalData) : jsString(&globalData, name.ustring()));

Can this be done with construction instead of assignment? Would that be a tiny bit better for performance?

This expression is long enough that it might be nice to share this code with an inline function instead of repeating it twice. The easiest way to do that would be an inline member function, or we could use an inline non-member function if we are doing it in construction.

Doesn’t jsString already handle the empty string case? Why do we need a special case for it here?

> Source/JavaScriptCore/runtime/Executable.h:481
> +        JSString* jsName() const { return m_jsName.get(); }

I would think of this as nameValue or wrappedName rather than jsName.
Comment 3 Oliver Hunt 2011-07-30 20:35:44 PDT
Comment on attachment 102447 [details]
Patch

r- because i just copied the old logic (which did an empty string check) and i don't want to just blindly commit.

That said, we do have to do the setting of m_jsName late as jsString() may perform a gc allocation, and it is _never_ safe to do GC allocation in the initializer list (you may end up doing a gc sweep midway through executing your initializer list, and then you end up not marking yourself correctly :-( )
Comment 4 Oliver Hunt 2011-08-02 17:18:03 PDT
Created attachment 102717 [details]
Patch
Comment 5 Gavin Barraclough 2011-08-02 17:26:12 PDT
Comment on attachment 102717 [details]
Patch

You may want to rename jsName to nameValue per Darin's suggestion, and functionNameOffset() should probably return a size_t.  Otherwise all looks good.
Comment 6 Oliver Hunt 2011-08-02 17:32:45 PDT
Created attachment 102720 [details]
Patch
Comment 7 Oliver Hunt 2011-08-02 17:41:49 PDT
Committed r92250: <http://trac.webkit.org/changeset/92250>