@@ -8,17 +8,21 @@ package kotlinx.collections.immutable.implementations.immutableList
8
8
import kotlinx.collections.immutable.ImmutableList
9
9
import kotlinx.collections.immutable.PersistentList
10
10
import kotlinx.collections.immutable.mutate
11
+ import kotlinx.collections.immutable.internal.ListImplementation.checkPositionIndex
11
12
12
13
public abstract class AbstractPersistentList <E > : PersistentList <E >, AbstractList <E >() {
13
14
override fun subList (fromIndex : Int , toIndex : Int ): ImmutableList <E > {
14
15
return super <PersistentList >.subList(fromIndex, toIndex)
15
16
}
16
17
17
18
override fun addAll (elements : Collection <E >): PersistentList <E > {
19
+ if (elements.isEmpty()) return this
18
20
return mutate { it.addAll(elements) }
19
21
}
20
22
21
23
override fun addAll (index : Int , c : Collection <E >): PersistentList <E > {
24
+ checkPositionIndex(index, size)
25
+ if (c.isEmpty()) return this
22
26
return mutate { it.addAll(index, c) }
23
27
}
24
28
@@ -31,10 +35,12 @@ public abstract class AbstractPersistentList<E> : PersistentList<E>, AbstractLis
31
35
}
32
36
33
37
override fun removeAll (elements : Collection <E >): PersistentList <E > {
38
+ if (elements.isEmpty()) return this
34
39
return removeAll { elements.contains(it) }
35
40
}
36
41
37
42
override fun retainAll (elements : Collection <E >): PersistentList <E > {
43
+ if (elements.isEmpty()) return persistentVectorOf()
38
44
return removeAll { ! elements.contains(it) }
39
45
}
40
46
0 commit comments