Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare character code constants per file #13500

Merged
merged 1 commit into from
Apr 11, 2024
Merged

Conversation

adamwathan
Copy link
Member

This PR effectively reverts #13497 but preserves the naming improvements that makes the name of each constant consistent between files.

I noticed when benchmarking segment that objects access like Token.OPEN_CURLY made the function 25x slower (!) so we should at a minimum import all of the character codes directly instead of using import * as Token from ....

I feel like since these aren't application-specific constants there's no harm in just redeclaring them in each file anyways — BACKSLASH is going to be 0x5c until the end of time, there's no risk that we have to update that value and now have to update it in more than one place. This also reduces the number of dependencies between files which is nice if we ever wanted to publish anything here as a separate package for any reason.

@RobinMalfait
Copy link
Contributor

A note for future reference: this 25x slowdown only happens when running benchmarks and tests on the raw source code. The final dist files don't have this issue because the constants are inlined.

@RobinMalfait RobinMalfait merged commit 0060508 into next Apr 11, 2024
1 check passed
@RobinMalfait RobinMalfait deleted the inline-char-codes branch April 11, 2024 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants