Files
ValueScript/inputs/passing/copyCounting/arrayRef.ts
Andrew Morris 264b8dee40 remove_noops
2023-06-30 17:19:28 +10:00

24 lines
461 B
TypeScript

//! test_output(0)
/// <reference path="../../../concept-code/vs.d.ts" />
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;
}