Files
ValueScript/inputs/passing/copyCounting/arrayRef.ts
2023-06-22 09:30:40 +10:00

22 lines
405 B
TypeScript

//! test_output(0)
export default function main() {
return measure(true) - measure(false);
}
function measure(ref: boolean) {
const x = Debug.makeCopyCounter("x");
let arr = [x, "y", "z"];
if (ref) {
// Evaluating (arr) can cause it to be stored in a temporary. If this temporary persists it
// causes the mutation below to copy.
arr[1];
}
arr[2] = "zz";
return x.count;
}