[FIR] Fix ArrayMapImpl.iterator()
This commit is contained in:
@@ -95,33 +95,20 @@ internal class ArrayMapImpl<T : Any> : ArrayMap<T>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun iterator(): Iterator<T> {
|
override fun iterator(): Iterator<T> {
|
||||||
return object : Iterator<T> {
|
return object : AbstractIterator<T>() {
|
||||||
private var currentIndex = -1
|
private var index = -1
|
||||||
private var nextIndex = 0
|
|
||||||
|
|
||||||
override fun hasNext(): Boolean {
|
override fun computeNext() {
|
||||||
if (nextIndex < 0) return false
|
do {
|
||||||
while (nextIndex < data.size && data[nextIndex] == null) {
|
index++
|
||||||
nextIndex++
|
} while (index < data.size && data[index] == null)
|
||||||
}
|
if (index >= data.size) {
|
||||||
return if (nextIndex >= data.size) {
|
done()
|
||||||
nextIndex = -1
|
|
||||||
false
|
|
||||||
} else {
|
} else {
|
||||||
true
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
setNext(data[index] as T)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun next(): T {
|
|
||||||
if (!hasNext()) throw NoSuchElementException()
|
|
||||||
if (currentIndex < 0) {
|
|
||||||
currentIndex = nextIndex
|
|
||||||
}
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
val result = data[currentIndex] as T
|
|
||||||
currentIndex = nextIndex++
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user