mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-06 08:23:19 +08:00
`for (let i = 0; i < s.length; i++) if (s[i] === " ") n++` and the same loop over `s.charAt(i)` got no loop version: `s[i]` lowers to charAt, and the version covered only charCodeAt reads. Each character paid the inline helper's ASCII and bounds tests and kept its opaque fallback. `const c = s[i]; if (c >= "a" && c <= "z") n++` also built the character string and compared strings twice. - The typed-array loop version covers `s.charAt(index)` like `s.charCodeAt(index)`, and a counted loop that reads either at its counter takes an integer counter. In the fast copy, a charAt used as a string is the immortal one-character string for its byte, and the equality and switch rewrites to charCodeAt read the byte. - A comparison of `s.charAt(i)` with a one-unit literal compares the code unit, as the equality does. An index out of range reads "", which is below every one-unit literal; its unit read is NaN, which the unordered predicates count as below. - A const string local initialized from a one-argument charAt and used only in one-unit equalities, comparisons and switches holds the code unit instead (char-unit-locals.ts).