Bug 119335

Summary: Use emptyString instead of String("")
Product: WebKit Reporter: Kwang Yul Seo <skyul>
Component: WebCore Misc.Assignee: Kwang Yul Seo <skyul>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, darin
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch darin: review+

Description Kwang Yul Seo 2013-07-31 04:57:56 PDT
Use emptyString() instead of String("") because it is better style and faster. This is a followup to r116908, removing all occurrences of String("") from WebKit.
Comment 1 Kwang Yul Seo 2013-07-31 05:01:38 PDT
Created attachment 207837 [details]
Patch
Comment 2 Kwang Yul Seo 2013-07-31 05:04:19 PDT
If we always prefer emptyString() to String(""), why don't we add an assertion to the String constructor to prevent "" from being passed to the constructor?
Comment 3 Darin Adler 2013-07-31 12:32:57 PDT
(In reply to comment #2)
> If we always prefer emptyString() to String(""), why don't we add an assertion to the String constructor to prevent "" from being passed to the constructor?

We don’t have any reason to allow String(""). But we do want to allow String(x) where x is a variable or argument of type const char* that just happens to be "".
Comment 4 Benjamin Poulain 2013-07-31 13:42:11 PDT
(In reply to comment #0)
> Use emptyString() instead of String("") because it is better style and faster. This is a followup to r116908, removing all occurrences of String("") from WebKit.

String("") is faster than emptyString() when you need a +1 ref string.

emptyString() return a reference, which is then ref()ed on the call site. String("") does pretty much the same thing but ref() on the callee side.

This is just for info, I don't mind if this patch lands.
Comment 5 Kwang Yul Seo 2013-07-31 16:51:21 PDT
(In reply to comment #4)
> String("") is faster than emptyString() when you need a +1 ref string.
> 
> emptyString() return a reference, which is then ref()ed on the call site. String("") does pretty much the same thing but ref() on the callee side.
> 
> This is just for info, I don't mind if this patch lands.

Thanks for the info. I think it is good to update the EfficientStrings wiki page.
Comment 6 Kwang Yul Seo 2013-07-31 16:53:04 PDT
Committed r153546: <http://trac.webkit.org/changeset/153546>
Comment 7 Benjamin Poulain 2013-07-31 17:00:54 PDT
(In reply to comment #5)
> Thanks for the info. I think it is good to update the EfficientStrings wiki page.

We can also fix the problem. This https://bugs.webkit.org/show_bug.cgi?id=95793 needs an update.