[webkit-dev] Initializing String and AtomicString with literals

Benjamin Poulain benjamin at webkit.org
Fri Aug 24 20:00:13 PDT 2012


Dear webkit-dev,


Some recent changes improved the way we can use string classes with
literals.

There are 3 new constructors for initializing a string from a literal:
-String(ASCIILIteral):
http://trac.webkit.org/browser/trunk/Source/WTF/wtf/text/WTFString.h#L139
-String(const char[], ConstructFromLiteralTag)
-AtomicString(const char[], ConstructFromLiteralTag)

The differences with the regular char* constructor are:
-no memory is allocated for the bytes of the string.
-the characters are not copied to the heap
-String(const char[], ConstructFromLiteralTag) does not even access the
bytes of the string.

Those constructors are faster and use less memory in some cases.
I converted some of the generated code to use the new constructors. In the
future, please consider using ASCIILiteral() whenever constructing a
String, and ConstructFromLiteral for a AtomicString.

cheers,
Benjamin

PS: I started a Wiki page about the efficient use of the string classes:
http://trac.webkit.org/wiki/EfficientStrings
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20120824/936f6f6c/attachment.html>


More information about the webkit-dev mailing list