scanner: Avoid recomputing consumed index
55292dcc5e880dc06c9f88eff5b5de79ed8a320bf3c90c02503f876896166da4
`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
84a55f16
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 { |