diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/kClassCache.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/kClassCache.kt index 12e7aacba9b56..93422cc0f0c76 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/kClassCache.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/kClassCache.kt @@ -34,7 +34,7 @@ internal fun <T : Any> getOrCreateKotlinClass(jClass: Class<T>): KClassImpl<T> { @Suppress("UNCHECKED_CAST") val kClass = cached.get() as KClassImpl<T>? if (kClass?.jClass == jClass) { - return kClass!! + return kClass } } else if (cached != null) { @@ -51,7 +51,6 @@ internal fun <T : Any> getOrCreateKotlinClass(jClass: Class<T>): KClassImpl<T> { // This is the most unlikely case: we found a cached array of references of length at least 2 (can't be 1 because // the single element would be cached instead), and none of those classes is the one we're looking for val size = cached.size - // Don't use Array constructor because it creates a lambda val newArray = arrayOfNulls<WeakReference<KClassImpl<*>>>(size + 1) // Don't use Arrays.copyOf because it works reflectively System.arraycopy(cached, 0, newArray, 0, size) diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/pcollections/ConsPStack.java b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/pcollections/ConsPStack.java index 47a8452c69675..5d9f5883c1876 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/pcollections/ConsPStack.java +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/pcollections/ConsPStack.java @@ -32,8 +32,8 @@ public static <E> ConsPStack<E> empty() { return (ConsPStack<E>) EMPTY; } - private final E first; - private final ConsPStack<E> rest; + final E first; + final ConsPStack<E> rest; private final int size; private ConsPStack() { // EMPTY constructor diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/pcollections/HashPMap.java b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/pcollections/HashPMap.java index db2b8a247a485..c54d8f9213ffe 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/pcollections/HashPMap.java +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/pcollections/HashPMap.java @@ -28,7 +28,7 @@ public final class HashPMap<K, V> { @SuppressWarnings("unchecked") @NotNull public static <K, V> HashPMap<K, V> empty() { - return (HashPMap<K, V>) HashPMap.EMPTY; + return (HashPMap<K, V>) EMPTY; } private final IntTreePMap<ConsPStack<MapEntry<K, V>>> intMap; @@ -49,9 +49,12 @@ public boolean containsKey(Object key) { public V get(Object key) { ConsPStack<MapEntry<K, V>> entries = getEntries(key.hashCode()); - for (MapEntry<K, V> entry : entries) + while (entries != null && entries.size() > 0) { + MapEntry<K, V> entry = entries.first; if (entry.key.equals(key)) return entry.value; + entries = entries.rest; + } return null; } @@ -86,9 +89,11 @@ private ConsPStack<MapEntry<K, V>> getEntries(int hash) { private static <K, V> int keyIndexIn(ConsPStack<MapEntry<K, V>> entries, Object key) { int i = 0; - for (MapEntry<K, V> entry : entries) { + while (entries != null && entries.size() > 0) { + MapEntry<K, V> entry = entries.first; if (entry.key.equals(key)) return i; + entries = entries.rest; i++; } return -1;