Skip to content

Commit 782d866

Browse files
committed
Suppress unchecked casts where appropriate
1 parent 02341fe commit 782d866

14 files changed

+31
-2
lines changed

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableList/PersistentVector.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ internal class PersistentVector<E>(private val root: Array<Any?>,
8282
newRootNode[bufferIndex] = tail
8383
// don't delve into the leaf level
8484
} else {
85+
@Suppress("UNCHECKED_CAST")
8586
newRootNode[bufferIndex] = pushTail(newRootNode[bufferIndex] as Array<Any?>?, shift - LOG_MAX_BUFFER_SIZE, tail)
8687
}
8788
return newRootNode

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableList/PersistentVectorBuilder.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class PersistentVectorBuilder<E>(private var vector: PersistentList<E>,
162162

163163
val elementCarry = ObjectRef(null)
164164
val newRest = insertIntoRoot(root!!, rootShift, index, element, elementCarry)
165+
@Suppress("UNCHECKED_CAST")
165166
insertIntoTail(newRest, 0, elementCarry.value as E)
166167
}
167168

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableList/PersistentVectorMutableIterator.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ internal class PersistentVectorMutableIterator<T>(
5555

5656
lastIteratedIndex = index - 1
5757

58+
@Suppress("UNCHECKED_CAST")
5859
val trieIterator = this.trieIterator ?: return builder.tail[--index] as T
5960
if (index > trieIterator.size) {
61+
@Suppress("UNCHECKED_CAST")
6062
return builder.tail[--index - trieIterator.size] as T
6163
}
6264
index--
@@ -69,11 +71,13 @@ internal class PersistentVectorMutableIterator<T>(
6971

7072
lastIteratedIndex = index
7173

74+
@Suppress("UNCHECKED_CAST")
7275
val trieIterator = this.trieIterator ?: return builder.tail[index++] as T
7376
if (trieIterator.hasNext()) {
7477
index++
7578
return trieIterator.next()
7679
}
80+
@Suppress("UNCHECKED_CAST")
7781
return builder.tail[index++ - trieIterator.size] as T
7882
}
7983

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableList/SmallPersistentVector.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ internal class SmallPersistentVector<E>(private val buffer: Array<Any?>) : Immut
6262
val newBuffer = buffer.copyOf()
6363
var newSize = 0
6464
for (element in buffer) {
65+
@Suppress("UNCHECKED_CAST")
6566
if (!predicate(element as E)) {
6667
newBuffer[newSize++] = element
6768
}
@@ -134,12 +135,14 @@ internal class SmallPersistentVector<E>(private val buffer: Array<Any?>) : Immut
134135

135136
override fun listIterator(index: Int): ListIterator<E> {
136137
checkPositionIndex(index, size)
138+
@Suppress("UNCHECKED_CAST")
137139
return BufferIterator(buffer as Array<E>, index, size)
138140
}
139141

140142
override fun get(index: Int): E {
141143
// TODO: use elementAt(index)?
142144
checkElementIndex(index, size)
145+
@Suppress("UNCHECKED_CAST")
143146
return buffer[index] as E
144147
}
145148

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableList/TrieIterator.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ internal class TrieIterator<out E>(root: Array<Any?>,
4343
var shift = (height - startLevel) * LOG_MAX_BUFFER_SIZE
4444
var i = startLevel
4545
while (i < height) {
46+
@Suppress("UNCHECKED_CAST")
4647
path[i] = (path[i - 1] as Array<Any?>)[indexSegment(index, shift)]
4748
shift -= LOG_MAX_BUFFER_SIZE
4849
i += 1
@@ -64,6 +65,7 @@ internal class TrieIterator<out E>(root: Array<Any?>,
6465

6566
private fun elementAtCurrentIndex(): E {
6667
val leafBufferIndex = index and MAX_BUFFER_SIZE_MINUS_ONE
68+
@Suppress("UNCHECKED_CAST")
6769
return (path[height - 1] as Array<E>)[leafBufferIndex]
6870
}
6971

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableMap/PersistentHashMapBuilder.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,20 @@ internal class PersistentHashMapBuilder<K, V>(private var map: PersistentHashMap
7474

7575
override fun remove(key: K): V? {
7676
operationResult = null
77+
@Suppress("UNCHECKED_CAST")
7778
node = node.mutableRemove(key.hashCode(), key, 0, this) ?: TrieNode.EMPTY as TrieNode<K, V>
7879
return operationResult
7980
}
8081

8182
fun remove(key: K, value: V): Boolean {
8283
val oldSize = size
84+
@Suppress("UNCHECKED_CAST")
8385
node = node.mutableRemove(key.hashCode(), key, value, 0, this) ?: TrieNode.EMPTY as TrieNode<K, V>
8486
return oldSize != size
8587
}
8688

8789
override fun clear() {
90+
@Suppress("UNCHECKED_CAST")
8891
node = TrieNode.EMPTY as TrieNode<K, V>
8992
size = 0
9093
}

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableMap/PersistentHashMapBuilderContentIterators.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal class TrieNodeMutableEntriesIterator<K, V>(private val builder: Persist
2323
override fun next(): MutableMap.MutableEntry<K, V> {
2424
assert(hasNextKey())
2525
index += 2
26+
@Suppress("UNCHECKED_CAST")
2627
return MutableMapEntry(builder, buffer[index - 2] as K, buffer[index - 1] as V)
2728
}
2829
}

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableMap/PersistentHashMapContentIterators.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal abstract class TrieNodeBaseIterator<out K, out V, out T> : Iterator<T>
2424

2525
fun currentKey(): K {
2626
assert(hasNextKey())
27+
@Suppress("UNCHECKED_CAST")
2728
return buffer[index] as K
2829
}
2930

@@ -39,6 +40,7 @@ internal abstract class TrieNodeBaseIterator<out K, out V, out T> : Iterator<T>
3940

4041
fun currentNode(): TrieNode<out K, out V> {
4142
assert(hasNextNode())
43+
@Suppress("UNCHECKED_CAST")
4244
return buffer[index] as TrieNode<K, V>
4345
}
4446

@@ -56,6 +58,7 @@ internal class TrieNodeKeysIterator<out K, out V> : TrieNodeBaseIterator<K, V, K
5658
override fun next(): K {
5759
assert(hasNextKey())
5860
index += 2
61+
@Suppress("UNCHECKED_CAST")
5962
return buffer[index - 2] as K
6063
}
6164
}
@@ -64,6 +67,7 @@ internal class TrieNodeValuesIterator<out K, out V> : TrieNodeBaseIterator<K, V,
6467
override fun next(): V {
6568
assert(hasNextKey())
6669
index += 2
70+
@Suppress("UNCHECKED_CAST")
6771
return buffer[index - 1] as V
6872
}
6973
}
@@ -72,6 +76,7 @@ internal class TrieNodeEntriesIterator<out K, out V> : TrieNodeBaseIterator<K, V
7276
override fun next(): Map.Entry<K, V> {
7377
assert(hasNextKey())
7478
index += 2
79+
@Suppress("UNCHECKED_CAST")
7580
return MapEntry(buffer[index - 2] as K, buffer[index - 1] as V)
7681
}
7782
}

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableSet/PersistentHashSet.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal class PersistentHashSet<E>(internal val node: TrieNode<E>,
6363
}
6464

6565
internal companion object {
66-
private val EMPTY = PersistentHashSet(TrieNode.EMPTY, 0)
66+
private val EMPTY = PersistentHashSet<Nothing>(TrieNode.EMPTY, 0)
6767
internal fun <E> emptyOf(): PersistentSet<E> = PersistentHashSet.EMPTY
6868
}
6969
}

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableSet/PersistentHashSetBuilder.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ internal class PersistentHashSetBuilder<E>(private var set: PersistentHashSet<E>
5454

5555
override fun remove(element: E): Boolean {
5656
val size = this.size
57+
@Suppress("UNCHECKED_CAST")
5758
node = node.mutableRemove(element.hashCode(), element, 0, this) ?: TrieNode.EMPTY as TrieNode<E>
5859
return size != this.size
5960
}
6061

6162
override fun clear() {
63+
@Suppress("UNCHECKED_CAST")
6264
node = TrieNode.EMPTY as TrieNode<E>
6365
size = 0
6466
}

0 commit comments

Comments
 (0)