From bdf8e6f3a5048e5abfa97db8e88f00a01d4c4f65 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 15 Feb 2023 14:49:08 +0200 Subject: [PATCH] [FIR] Extend capacity of `ArrayMapImpl` until it fits required size There are cases when we have some indices in TypeRegistry left from previous compilations, so registering new service may increase index not by one So such situation is possible: First compilation (jvm project): register 20 different jvm services in session + one from compiler plugin (with index 21) Second compilation (common project): register only 10 common services in session + one from compiler plugin (with index 21) *numbers are imaginary And in this situation increasing `ArrayMapImpl.data` size only one time may not cover required index ^KT-56685 Fixed --- .../src/org/jetbrains/kotlin/util/ArrayMap.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/compiler.common/src/org/jetbrains/kotlin/util/ArrayMap.kt b/core/compiler.common/src/org/jetbrains/kotlin/util/ArrayMap.kt index 1feab358db5..63434ab2e80 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/util/ArrayMap.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/util/ArrayMap.kt @@ -87,9 +87,12 @@ internal class ArrayMapImpl private constructor( private fun ensureCapacity(index: Int) { - if (data.size <= index) { - data = data.copyOf(data.size * INCREASE_K) - } + if (data.size > index) return + var newSize = data.size + do { + newSize *= INCREASE_K + } while (newSize <= index) + data = data.copyOf(newSize) } override operator fun set(index: Int, value: T) {