Repository navigation
Decode CSS hex colors in one pass - #60535
Merged
Merged
Conversation
ide
force-pushed
the
@ide/css-hex-single-pass
branch
from
December 4, 2026 11:32
65af61e to
1c1cba5
Compare
`parseCSSHexColor` currently reads each digit twice, once to validate it and once to assemble the color. Use a compile-time lookup table to decode each byte once and reuse the decoded value for both steps. The parser accepts the same case-insensitive 3-, 4-, 6- and 8-digit forms. [CSS Color 4 §5.2](https://www.w3.org/TR/css-color-4/#hex-notation) The C++ `CSSColor` suite passes. The new cases check mixed-case shorthand and full colors at compile time and reject invalid lengths, digits and non-ASCII bytes at runtime. `yarn cxx-api-validate` passes with Doxygen 1.16.1. An optimized C++ benchmark on Apple M6 alternates valid colors of all four lengths. The median across five interleaved runs, measured with `proc_pid_rusage`, falls from 155.84 to 61.01 retired instructions per valid parse and from 54.88 to 42.38 per parse for inputs with invalid lengths or digits. The result checksums match. Signed-off-by: James Ide <ide@expo.dev>
ide
force-pushed
the
@ide/css-hex-single-pass
branch
from
December 4, 2026 12:35
1c1cba5 to
77eba87
Compare
ide
marked this pull request as ready for review
December 4, 2026 14:37
Abbondanzo
approved these changes
Dec 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
parseCSSHexColorcurrently reads each digit twice, once to validate it and once to assemble the color. Use a compile-time lookup table to decode each byte once and reuse the decoded value for both steps. The parser accepts the same case-insensitive 3-, 4-, 6- and 8-digit forms. CSS Color 4 §5.2Changelog:
[INTERNAL] [CHANGED] - Decode CSS hex colors in one pass.
Test Plan:
The C++
CSSColorsuite passes. The new cases check mixed-case shorthand and full colors at compile time and reject invalid lengths, digits and non-ASCII bytes at runtime.yarn cxx-api-validatepasses with Doxygen 1.16.1.An optimized C++ benchmark on Apple M6 alternates valid colors of all four lengths. The median across five interleaved runs, measured with
proc_pid_rusage, falls from 155.84 to 61.01 retired instructions per valid parse and from 54.88 to 42.38 per parse for inputs with invalid lengths or digits. The result checksums match.