mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
Typed-array loop versions applied only to for loops, so a scanner written with while loops, such as `while (pos < end && bytes[pos] === 32) pos++`, kept one bounds test per access. A while loop counter is now a number local that the loop changes only by positive integer increments (`c = c + k`, `c++`, `c = (c + k) | 0`) written as statements of its body, blocks, branches and nested while loops. An access at `counter + d` after a condition compared the counter below a loop-invariant bound, with no increment since, is in bounds for the whole loop when the guard finds the counter's entry value an exact integer of at least -d and the bound at most the length minus the access's extent. A counter with a `| 0` increment also needs its loops' bounds at most 2^31 minus its increments, so it never wraps. A fixed check (a statically ranged index) now needs an end below 2^31. The counter of a loop to a number[]'s length whose length the loop may change reaches 2^32 - 2, and its typed-array accesses got a guard no typed array passes and a second copy of the loop.