3 ms·
As someone who hasn't used swift, are there same array covariance problems as C#/Java due to implicit casting?
by higerordermap 6y ago
As someone who hasn't used swift, are there same array covariance problems as C#/Java due to implicit casting?
- KMag 6y agoI was wondering the same thing. The linked article explains that they use an extra layer of indirection to perform copy-on-write for implicit upcasts. So, you can upcast in O(1), but your first write to the upcast array has an O(N) cost. The upcast is type sound, unlike Java, but at the cost of an extra indirection, and a big hit for the first mutation after upcast. I would have been tempted to instead just have immutable array references that could be freely upcast, but this is also an elegant and safe solution.
- deleted 6y ago[deleted]