PEGO

M040: Character Scan Loops

A value-free repetition of one character need not build an element value or create a full backtracking mark for every iteration. A scan loop performs the repeated membership or any-character test directly.

Mechanism and Invariants

The compiler recognizes eligible single-character class or dot repetitions only when their result is unused. It preserves minimum/maximum repetition bounds, input positions, terminal failure expectations and examined input. Captures, actions or compound expressions that require per-element state remain on the general repetition path. The bytecode compiler emits SCAN; generated emitters produce an equivalent loop. Stream scans must retain reader loading behavior.

Scope and State

Applied by default to eligible value-free repetitions in closure, both VMs, generated Go Node/recognition, typed Go and TypeScript. Value-building repetitions are outside this specialization.

Reference Control

No shared same-source scan-disable comparator is maintained. A value-building parse changes the operation and is not an isolated reference.

Evidence and Implementation

Record 008 combines scan lowering with unmemoized-call changes and reports recognition reductions such as CSV 24 to 18 ms. Record 011 carries scan loops into generated Go. Those historical combined measurements do not assign the whole improvement to scanning or establish current performance in all six targets.

Evidence records: 008.

Source owners: Walker.scanRepeat, closureBuilder.ScanRepeat, SCAN lowering, Scans pass, Flow scan lowering, which lowers the scans of generated Go and TypeScript.

The comparison policy distinguishes same-source controls, historical changes and full checkpoints.

Related mechanisms: E010, M020.

Optimization Catalog