Skip to content

Conversation

nevans
Copy link
Collaborator

@nevans nevans commented Nov 3, 2023

Using @str.getbyte(@pos) == int rather than @str[@pos] == chr avoids the allocation of a temporary string object and allows direct identity comparison. This gives a speedup of ~5% to most parser benchmarks.

Using `string.getbyte(pos)` rather than `string[pos]` avoids the
allocation of a temporary string object.  This gives a speedup of ~5%
to most benchmarks.
@nevans nevans changed the title ⚡ Parse expected chars using String#getbyte ⚡ Parse expected chars using String#getbyte Nov 3, 2023
@nevans nevans merged commit 9ccc31e into ruby:master Nov 3, 2023
@nevans nevans deleted the parser/char_matchers branch November 3, 2023 03:08
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.

1 participant