If you have a large array named `foo` (let's say i...
# language-proposals
b
If you have a large array named
foo
(let's say it's 1GB) and then you say
var bar = foo
, a "copy" is made, yes. And I'm not 100% sure how, but no delay is incurred. I suspect that you get a new pointer, and any changes you make are reflected as diffs. Also,
let foo = "foo"; let bar = foo
, IIRC, makes
foo
and
bar
point to the same memory, which is safe because neither can be mutated.
v
Unfortunately, there are no diffs. That would be like a Git inside an array.
Swift copies lazily. On
var bar = foo
nothing happens until you mutate
bar
. Then the whole 1GB is copied.
I admit I have a very strong negative opinion of this part of Swift. Sorry if I sound bitter