WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
Bug 238263
Avoid unnecessary String constructor under FunctionExecutable::toStringSlow()
https://bugs.webkit.org/show_bug.cgi?id=238263
Summary
Avoid unnecessary String constructor under FunctionExecutable::toStringSlow()
Chris Dumez
Reported
2022-03-23 08:56:12 PDT
Avoid unnecessary String constructor under FunctionExecutable::toStringSlow().
Attachments
Patch
(1.75 KB, patch)
2022-03-23 08:57 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(1.70 KB, patch)
2022-03-23 09:53 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
Chris Dumez
Comment 1
2022-03-23 08:57:12 PDT
Created
attachment 455505
[details]
Patch
Darin Adler
Comment 2
2022-03-23 09:02:40 PDT
Comment on
attachment 455505
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=455505&action=review
> Source/JavaScriptCore/runtime/FunctionExecutable.cpp:144 > - String functionHeader; > + ASCIILiteral functionHeader = ASCIILiteral::null();
A few other thoughts: Why ASCIILiteral::null() here, but ""_s below? I’m not familiar with the variadic jsMakeNontrivialString. Does jsMakeNontrivialString benefit from this being an ASCIILiteral rather than a const char* or a StringView? Since src is a StringView I get the impression that we don’t need to make a String so not sure why ASCIILiteral is better than const char*. I’m sort of surprised that this idiom is jsMakeNontrivialString instead of just jsNontrivialString(makeString()). I think I would have done: auto functionHeader = "";
Chris Dumez
Comment 3
2022-03-23 09:10:17 PDT
(In reply to Darin Adler from
comment #2
)
> Comment on
attachment 455505
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=455505&action=review
> > > Source/JavaScriptCore/runtime/FunctionExecutable.cpp:144 > > - String functionHeader; > > + ASCIILiteral functionHeader = ASCIILiteral::null(); > > A few other thoughts: Why ASCIILiteral::null() here, but ""_s below? I’m not > familiar with the variadic jsMakeNontrivialString. Does > jsMakeNontrivialString benefit from this being an ASCIILiteral rather than a > const char* or a StringView? Since src is a StringView I get the impression > that we don’t need to make a String so not sure why ASCIILiteral is better > than const char*. I’m sort of surprised that this idiom is > jsMakeNontrivialString instead of just jsNontrivialString(makeString()). > > I think I would have done: > > auto functionHeader = "";
Technically, the initialization value doesn't matter much since the switch below handles all enum values. Previously, the initialization value was a null string, not an empty string. ASCIILiteral::null() thus seemed closer to pre-existing code than ""_s. That said, I don't mind initializing to _""s. jsMakeNontrivialString() doesn't benefit from using an ASCIILiteral here. Using an ASCIILiteral also doesn't hurt as far as I can tell. Using ASCIILiteral also could be helpful for perf if we ever decide to store the string length as a data member in ASCIILiteral. I think it is best practice to use _s for all String literals in WebKit. It should always be as good or faster than "". If we have API that is slower with an ASCIILiteral, I think that API would need to be fixed.
Chris Dumez
Comment 4
2022-03-23 09:53:15 PDT
Created
attachment 455509
[details]
Patch
EWS
Comment 5
2022-03-23 11:38:32 PDT
Committed
r291755
(
248786@main
): <
https://commits.webkit.org/248786@main
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 455509
[details]
.
Radar WebKit Bug Importer
Comment 6
2022-03-23 11:39:46 PDT
<
rdar://problem/90713418
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug