Implement optimized removeRange for ArrayDeque #KT-64956

Test ArrayDeque with size 15. With the existing sizes the removeRange
implementation couldn't reach the maximum number of iterations - 3.

Benchmark results for ArrayDeque.subList().clear() that uses
removeRange() can be found here:
https://github.com/qurbonzoda/KotlinArrayDequeBenchmarks/tree/master/results
This commit is contained in:
Abduqodiri Qurbonzoda
2024-01-30 16:01:14 +02:00
committed by Space Team
parent 240a423bed
commit b67ebf36a2
5 changed files with 128 additions and 7 deletions
@@ -221,6 +221,13 @@ public actual abstract class AbstractMutableList<E> protected actual constructor
return list.set(fromIndex + index, element)
}
override fun removeRange(fromIndex: Int, toIndex: Int) {
checkForComodification()
list.removeRange(this.fromIndex + fromIndex, this.fromIndex + toIndex)
_size -= toIndex - fromIndex
modCount = list.modCount
}
override val size: Int
get() {
checkForComodification()