scanner: Avoid recomputing consumed index
69f92d23e58d13e927be1bb4273a24e18d4eb5fb823c7c187def90761f109bc6
`advance` incremented the cursor before loading the consumed byte. Each call therefore subtracted one from the updated cursor. Load the byte first and then increment the cursor. This removes redundant arithmetic from the scanner hot path. Assisted-by: Codex:gpt-5.6-sol
1 parent
438a079f
lib/std/lang/scanner.rad
+2 -1
| 257 | 257 | return s.source[s.cursor + 1]; |
|
| 258 | 258 | } |
|
| 259 | 259 | ||
| 260 | 260 | /// Advance scanner and return the character that was consumed. |
|
| 261 | 261 | fn advance(s: *mut Scanner) -> u8 { |
|
| 262 | + | let ch = s.source[s.cursor]; |
|
| 262 | 263 | set s.cursor += 1; |
|
| 263 | - | return s.source[s.cursor - 1]; |
|
| 264 | + | return ch; |
|
| 264 | 265 | } |
|
| 265 | 266 | ||
| 266 | 267 | /// Consume the expected character if it matches the current position. |
|
| 267 | 268 | fn consume(s: *mut Scanner, expected: u8) -> bool { |
|
| 268 | 269 | if let c = current(s); c == expected { |