Fix IntArrayList deprecation warning in JvmDependenciesIndexImpl

Copy relevant parts of deprecated IntelliJ's IntArrayList to a new util
class. Also fix some minor IDE inspections.
This commit is contained in:
Alexander Udalov
2021-01-12 14:25:15 +01:00
parent 8ae19f5cd7
commit ee7691f1ad
2 changed files with 42 additions and 4 deletions
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.utils
// Based on com.intellij.util.containers.IntArrayList.
class IntArrayList(initialCapacity: Int) {
private var data = IntArray(initialCapacity)
private var size = 0
fun trimToSize() {
if (size < data.size) {
data = data.copyOf(size)
}
}
private fun ensureCapacity(minCapacity: Int) {
if (minCapacity > data.size) {
data = data.copyOf(maxOf(data.size * 3 / 2 + 1, minCapacity))
}
}
fun size(): Int = size
val isEmpty: Boolean get() = size == 0
operator fun get(index: Int): Int = data[index]
fun add(o: Int) {
ensureCapacity(size + 1)
data[size++] = o
}
override fun toString(): String =
(0 until size).joinToString(", ", "[", "]") { this[it].toString() }
}