-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Simplify sequential character checks in Crystal lexer #12699
Simplify sequential character checks in Crystal lexer #12699
Conversation
I think I tried such an optimization in the past and it made things slightly slower. It might be worth providing a benchmark. |
100 runs against
50 runs against all Crystal files in the
@asterite I don't see a reproducible slowdown as a result of this change. |
The worst performing and reproducible benchmark is
Are there any oppositions to turning this helper into a macro? Also know it's not ideal practice, but adding
|
You could also try making the method private. That should encourage inlining. |
I think the benchmark should just be parsing. Like using Benchmark.ips and code that just parses. I might try it later. |
I just ran a benchmark and there's no noticeable difference, so 👍 |
A small refactor, adding
char_sequence?
method to check a sequence of characters.This makes it a bit easier to read conditionals in the Crystal lexer.
Also included...
case
expression is more readable than chained conditionals after an assignment in the condition..in?
, and cleanups related to its use.