[webkit-dev] some WebCore::String plans

Darin Adler darin at apple.com
Tue Dec 18 10:51:29 PST 2007

The WebCore::String class needs some work. I have some plans to  
improve it. Here's an outline of what I have in mind.

- eliminate all non-const functions from StringImpl; fixes tricky  
sharing semantics
- change all uses of const StringImpl* to just plain StringImpl*  
because there will no longer be any real difference between these types
- then, once RefCounted is made thread-safe, then we could remove the  
copy() function altogether, since the only reason to use it would be  
thread safety

- change functions that return StringImpl* to return  
PassRefPtr<StringImpl> instead, if they sometimes make a new object;  
makes it harder to accidentally leak
- change functions that take StringImpl* to take  
PassRefPtr<StringImpl> instead if they take ownership; can reduce  
reference count churn
- make a release() function on String that returns a  
PassRefPtr<StringImpl>; can reduce reference count churn

- eliminate functions that return a StringImpl* from StringImpl,  
because it's to easy to misunderstand and think these modify the  
string in place
- eliminate functions that return a String from String -- also easy to  
use wrong for the same reasons

- change TextStream into a class named StringBuilder for clients that  
are building up strings (name inspired by Java); it will have get()  
and release() functions that will return PassRefPtr<StringImpl>
- add functions that take a PassRefPtr<StringImpl> and return a  
PassRefPtr<StringImpl> for many string operations, since those can  
optimize the "only one reference" case and re-use the same character  
buffer; change the String class to use those as appropriate
- rename the String::impl() function to String::get() to match other  
RefPtr classes
- consider eliminating String and using RefPtr<StringImpl> at most or  
all call sites
- consider changing call sites that take a const String& to instead  
take StringImpl* or PassRefPtr<StringImpl>

- rename StringImpl to SharedString
- consider renaming WebCore::String to StringRefPtr since it's a  
lightweight wrapper around a RefPtr; one benefit is that it would  
allow us to eliminate the header name PlatformString.h

These plans are still a bit rough. Please let me know what you think.  
Depending on what feedback I get, I might make a Wiki page about this.

Some of this I will do soon. Some of it is longer-term.

     -- Darin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.webkit.org/pipermail/webkit-dev/attachments/20071218/d37dce41/attachment.html

More information about the webkit-dev mailing list