3 ms·
Most languages just clone all day long, it's not that bad, rust clones (like most languages) are just to the first reference counted pointer after all.
by gpm 6y ago
Most languages just clone all day long, it's not that bad, rust clones (like most languages) are just to the first reference counted pointer after all.
- the_duke 6y agoWell, yes and no. Eg cloning a string leads to an extra allocation and a memcopy. If you want to get a similar performance profile to GC languages, you have to stick your types behind a `Rc<T>>/Arc<T>` or `Rc<RefCell<T>> / Arc<Mutex<T>>` if you need mutability. But modern allocators hold up pretty well to a GC, which amortizes the allocations. The extra memcopying can be less detrimental than one might think.
- throwaway894345 6y ago“Yes and no” is too generous; most languages clone only very infrequently (basically only for primitives where there is no distinction between a deep and shallow copy). For complex types (objects and maps and lists) they pass references (sometimes “fat” references, but nevertheless, not a clone).