Open chuckjaz opened 8 months ago
Yes, this is quite essential. For instance, the IJ Platform uses this for the implementation of extensions. A pattern like "get all extensions and merge with another one" is quite popular. If it will behave as described above, it will provide a good reason to prefer the kotlinx collections library over the Java immutables one.
When a
PersistentVector<T>
is added to anotherPersistentVector<T>
throughaddAll
this can be optimized and, when the shift alligns, layers of the vector, as a whole, can be copied over instead of copying individual elements. Even if the shifts don't allgin,copyInto
can be used instead of going through theaddAll
of thebuilder
which can avoid several otherwise unncessary allocations and virtual dispatches.A similar technique can be used for the
TrieNode
for thePersistentHashMap
but the special cases end up not being nearly as rare as it will often be the case when wholeTrieNode
s can be copied from onePersistentHashMap
to another.