Chromium Code Reviews
DescriptionAvoid copying strings when parsing CSS colors on the slow path.
parseHexColor was always calling value().toString() forcing a string
copy of every hex color inside the parser. We can instead change
Color::parseHexColor to take a StringView and pass value() directly
avoiding this string copy.
CSSTokenizer::consumeName() also has a fast path which avoids making
string copies when the token value doesn't contain escapes. This path
didn't work when the input to the parser was a value that's not
followed by a semi-colon (ex. color = "#ccc" in JS) because
peekWithoutReplacement would return NUL when we accessed the first out
of range position, which then aborted the loop, and made us go down the
string copy path usually used for escapes.
This patch makes parsing colors on the slow path 2x faster:
ex.
for (var i = 0; i < 50000; ++i) {
span.style.color = " #ddd"; // note the space before the #.
The color parsing fast path still seems about 2x faster than this
optimized path, but this patch gets us much closer to not needing the
color parsing fast path and makes whitespace in your colors less
terrible for performance.
The patch will also help CSS parsing in general by avoiding string
copies for every hex color.
BUG=605792
Committed: https://crrev.com/0d4987c045a9cbc5033295f0aee38a2456f039bf
Cr-Commit-Position: refs/heads/master@{#402097}
Patch Set 1 #Patch Set 2 : missing else. #
Total comments: 1
Messages
Total messages: 13 (6 generated)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||