mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-08 08:44:37 +08:00
A slice whose every reader only borrows it is written into a stack buffer instead of a heap allocation. A slice stored in a record field counted as kept, so a tokenizer's `const text = source.slice(start, i); const t = token(kind, text, start); sum += weight(t);` allocated and freed a string per token even though `t` is read only for `t.text.length`. A slice local stored directly in a field of a stable record local, built by a record literal or by a factory that only returns a record literal of its parameters, is now lent when the record is only projected: its field reads are lending reads, and it is passed only to record parameters whose bodies read that field only in lending positions (a fixpoint, like the one for lent string parameters). A record that is returned, stored, captured or passed anywhere else keeps the slice on the heap. includes, indexOf and lastIndexOf on string arrays now lend their search argument.