Bug 159789 - Use emptyString() instead of "" when possible
Summary: Use emptyString() instead of "" when possible
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-14 15:15 PDT by Chris Dumez
Modified: 2016-07-15 13:19 PDT (History)
5 users (show)

See Also:


Attachments
Patch (22.52 KB, patch)
2016-07-14 15:23 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2016-07-14 15:15:26 PDT
Use emptyString() instead of "" when possible to reduce String allocations.
Comment 1 Chris Dumez 2016-07-14 15:23:20 PDT
Created attachment 283691 [details]
Patch
Comment 2 Chris Dumez 2016-07-14 16:18:40 PDT
Comment on attachment 283691 [details]
Patch

Clearing flags on attachment: 283691

Committed r203250: <http://trac.webkit.org/changeset/203250>
Comment 3 Chris Dumez 2016-07-14 16:18:45 PDT
All reviewed patches have been landed.  Closing bug.
Comment 4 Elliott Sprehn 2016-07-15 13:18:21 PDT
Does this actually save allocations? String("") does StringImpl::create(LChar*) which does strlen and then StringImpl::create(LChar*, unsigned) which does:

https://github.com/adobe/webkit/blob/master/Source/WTF/wtf/text/StringImpl.cpp#L255

    if (!characters || !length)
        return empty();

I think this patch saves branches and function calls, but not allocations?
Comment 5 Chris Dumez 2016-07-15 13:19:37 PDT
(In reply to comment #4)
> Does this actually save allocations? String("") does
> StringImpl::create(LChar*) which does strlen and then
> StringImpl::create(LChar*, unsigned) which does:
> 
> https://github.com/adobe/webkit/blob/master/Source/WTF/wtf/text/StringImpl.
> cpp#L255
> 
>     if (!characters || !length)
>         return empty();
> 
> I think this patch saves branches and function calls, but not allocations?

You're totally right Elliot, I did not know about this optimization in StringImpl.