Immutable Arrays
New Features:
- Add
shuffled()
&shuffled(random)
methods - Add
toMutableArray()
extension functions - Add
toTypedMutableArray()
extension functions - Add
referencesSameArrayAs(immutableArray)
method since referential equality isn't allowed for inline classes - Add
copyFrom(regularArray, startIndex, size)
companion factory function - Add
randomOrNull()
&randomOrNull(Random)
methods - Add
random()
&random(Random)
methods
Performance Improvements:
- Update
filter
,filterIndexed
, &filterNot
to switch from accumulating elements in a builder to capturing
accepted elements as single bits in anIntArray
and use bitwise operations to avoid branching. - Update
distinct()
to usefilter
with aHashSet
instead of callingtoSet().toImmutableArray()
to avoid using
the more expensiveLinkedHashSet
while still maintaining original ordering. This also returns the same instance when
all elements are already distinct. - Update
immutableArrayOf(...)
to avoid creating a temporary builder by using thecopyFrom
factory function - Update
regularArray.toImmutableArray()
to avoid creating a temporary builder by using thecopyFrom
factory
function - Update
plus
to concatenate an element with an Immutable Array without using builders. - Update
plus
to concatenate 2 Immutable Arrays without using builders. - Update
sortedWith
onImmutableArray<T>
to copy the elements witharraycopy
. - Update
partition
to usearraycopy
to copy from the left side of the buffer.