mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-07 08:33:50 +08:00
After the union fix, records-sort spent most of its time in the IR merge sort's element moves: every src[i] read retained the swapped `src` array and the element (scr_arr_get_ref), every dst[k] write released the old slot, and `dst` grew from an empty array. scr_arr_sort_values runs the IR helper's exact algorithm (same comparator call order) over borrowed slot copies of the private, compacted snapshot: - comparator calls use the callValue ABI (owned element arguments, an undefined `this` window, pending-exception check); - the array keeps owning every element and is untouched while user code runs, so the cycle collector and a throwing comparator see the original snapshot; the sorted permutation is published only after success; - f64 and reference-counted element types qualify (isSortValuesElement); unions with an undefined arm and checked/island values keep the IR. The new internal arrIntrinsic `sortValues` is validated, may throw, and is not reference-preserving.