[webkit-dev] Initializing String and AtomicString with literals

Adam Barth abarth at webkit.org
Fri Aug 24 22:18:29 PDT 2012


The wiki page says:

[[[
The difference between the version is if the length of the string is
included or not. Having the size given in the constructor makes the
constructor faster. Having the size also makes the code bigger, which
is a problem when the code is executed infrequently.
]]]

That description isn't 100% clear to me, but my reading of it is that
the ConstructFromLiteral version has the length of the string embedded
at the call site and therefore makes the code faster by increases the
code size.

Adam


On Fri, Aug 24, 2012 at 10:13 PM, Maciej Stachowiak <mjs at apple.com> wrote:
>
> What's the difference between the ASCIILiteral and ConstructFromLiteral
> versions?
>
>  - Maciej
>
> On Aug 24, 2012, at 8:00 PM, Benjamin Poulain <benjamin at webkit.org> wrote:
>
> 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
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev
>
>
>
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev
>


More information about the webkit-dev mailing list