mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-12 02:13:04 +08:00
The runtime appends to a string in place when the left operand is uniquely owned, but three common forms never got there: - `obj.field += s` on a plain class or record field kept a second reference to the old value, so every append copied the whole string. The compound assignment now reads a stored string field into a mutable local, stores "" into the field (no code runs in between: both operands are already strings), runs the self-append `old = old + rhs` and stores the result. - `s = s + a + b` copied per append: the self-append recognized only `s = s + x`. A concat chain whose leftmost operand is the target now takes the remaining operands as the suffix, in the same order. - `s += String.fromCharCode(c)` built a one-character string first. scr_str_concat_move_char_code appends the character, in place for ASCII. Self-appends also borrow the suffix instead of retaining it, and a discarded compound assignment no longer retains and releases its result.