Bug 159789

Summary: Use emptyString() instead of "" when possible
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebCore Misc.Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, commit-queue, esprehn, kling, koivisto
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

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.