-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
syntax: avoid a slice bounds check on every input byte
When our lexer peeks one byte or consumes one rune, we do a check like `p.bsp < len(p.bs)` followed by `p.bs[p.bsp]`. In practice this made a bounds check unnecessary, as we knew we had enough input bytes in p.bs to grab the byte at p.bsp, but since p.bsp was a signed integer, the compiler knew that in theory p.bsp could have overflowed to a negative value and caused a panic. In the past I tried swapping p.bsp from an int to an uint to solve this issue, but the compiler wasn't yet clever enough to take note. It seems like it now is: │ old │ new │ │ sec/op │ sec/op vs base │ Parse-8 14.86µ ± 1% 14.46µ ± 1% -2.74% (p=0.000 n=10)
- Loading branch information
Showing
2 changed files
with
12 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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