Skip to content

Decode CSS hex colors in one pass - #60535

Merged
Abbondanzo merged 1 commit into
react:mainfrom
expo:@ide/css-hex-single-pass
Dec 4, 2026
Merged

Abbondanzo merged 1 commit into
react:mainfrom
expo:@ide/css-hex-single-pass

Conversation

@ide

@ide ide commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

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

Changelog:

[INTERNAL] [CHANGED] - Decode CSS hex colors in one pass.

Test Plan:

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.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 4, 2026
@ide
ide force-pushed the @ide/css-hex-single-pass branch from 65af61e to 1c1cba5 Compare December 4, 2026 11:32
`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
ide force-pushed the @ide/css-hex-single-pass branch from 1c1cba5 to 77eba87 Compare December 4, 2026 12:35
@ide
ide marked this pull request as ready for review December 4, 2026 14:37
@Abbondanzo
Abbondanzo merged commit a174e2c into react:main Dec 4, 2026
99 checks passed
@ide
ide deleted the @ide/css-hex-single-pass branch December 5, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants