3 ms·
Would that not make passing around data expensive? Or are you expected to pass some kind of pointer instead?
by xrisk 9y ago
Would that not make passing around data expensive? Or are you expected to pass some kind of pointer instead?
- slavapestov 9y agoCopy-on-write alleviates some of the overhead. Copies are only performed where required to preserve value semantics.
- mantas 9y agoAll of these can be both mutable or immutable. And converted as needed let array = [1, 2, 3] var mutableArray = [4, 5, 6] var anotherMutable = array Not sure how much optimisation is done under the hood, but Swift compiler loves to complain about mutable structures that are not ever edited.
- masklinn 9y agoThese are all copy-on-write boxed types with value semantics: the value you pass around is a pointer (with some additional data) and Swift has mechanisms/API which let the implementor copy the backing buffer on mutation if necessary: https://developer.apple.com/documentation/swift/2429905-isknownuniquelyreferenced https://developer.apple.com/documentation/swift/2429905-iskn...