HomePhabricator Dev

Bug 1488697 - Make StringBuilder::ToString avoid repeated capacity and aliasing…

Description

Bug 1488697 - Make StringBuilder::ToString avoid repeated capacity and aliasing checks as well as terminator writes. r=smaug

  • Avoid the string implementation's capacity checks, since we know they succeed.
    • Avoid the string implementation's aliasing checks, since we know there's no aliasing.
    • Avoid writing the zero terminator more than once or out of sequence.
    • Use u"" literals when appending literals to a UTF-16 string.
    • Write runs of non-escaped code units instead of writing code unit by code unit in order to benefit from SIMD (either via memcpy or ConvertLatin1toUTF16).

This results in a 13% execution time reduction on desktop Haswell i7 when
getting the innerHTML of the body of the Selectors spec. (The WebKit
optimization target from https://bugs.webkit.org/show_bug.cgi?id=81214 .)

MozReview-Commit-ID: LAg3gkGJnpQ

Differential Revision: https://phabricator.services.mozilla.com/D5239