There are many places in Blink code where we want to know if the string contains only ASCII characters. This often happens when we want to get access to the strings UTF8 bytes using WebString::utf8 or StringUTF8Adaptor.
Today, each check involves scanning each character of the string, even if we know (via some property of a parser like our URL parser) that the string definitely only has ASCII characters. For many Strings we do this kind of scanning many times.
We should:
1. Cache a bit in StringImpl if the String contains only ASCII characters. This can be lazily set on the first call to containsOnlyASCII().
2. Add a setter (or constructor) to StringImpl which automatically sets the containsOnlyASCII bits. I could see this used in a few different places:
- substring()
- StringView::toString()
- String copies
- URL parts (e.g. KURL::host will always contain ascii, even if the ref part doesn't)
Comment 1 by bugdroid1@chromium.org
, Jan 5 2017