Add NotNull annotations to HashPMap

This commit is contained in:
Alexander Udalov
2014-07-01 16:32:06 +04:00
parent e60428b540
commit 7cbbeb257e
2 changed files with 8 additions and 3 deletions
@@ -24,7 +24,7 @@ import kotlin.reflect.jvm.internal.pcollections.HashPMap
// Arrays are needed because the same class can be loaded by different class loaders, which results in different Class instances.
// This variable is not volatile intentionally: we don't care if there's a data race on it and some KClass instances will be lost.
// We do care however about general performance on read access to it, thus no synchronization is done here whatsoever
private var FOREIGN_K_CLASSES = HashPMap.empty<String, Any>()!!
private var FOREIGN_K_CLASSES = HashPMap.empty<String, Any>()
// This function is invoked on each reflection access to Java classes, properties, etc. Performance is critical here.
fun <T> foreignKotlinClass(jClass: Class<T>): KClassImpl<T> {
@@ -55,11 +55,11 @@ fun <T> foreignKotlinClass(jClass: Class<T>): KClassImpl<T> {
System.arraycopy(cached, 0, newArray, 0, size)
val newKClass = KClassImpl<T>(jClass)
newArray[size] = WeakReference(newKClass)
FOREIGN_K_CLASSES = FOREIGN_K_CLASSES.plus(name, newArray)!!
FOREIGN_K_CLASSES = FOREIGN_K_CLASSES.plus(name, newArray)
return newKClass
}
val newKClass = KClassImpl<T>(jClass)
FOREIGN_K_CLASSES = FOREIGN_K_CLASSES.plus(name, WeakReference(newKClass))!!
FOREIGN_K_CLASSES = FOREIGN_K_CLASSES.plus(name, WeakReference(newKClass))
return newKClass
}
@@ -16,6 +16,8 @@
package kotlin.reflect.jvm.internal.pcollections;
import org.jetbrains.annotations.NotNull;
/**
* A persistent map from non-null keys to non-null values.
*/
@@ -23,6 +25,7 @@ public final class HashPMap<K, V> {
private static final HashPMap<Object, Object> EMPTY = new HashPMap<Object, Object>(IntTreePMap.<ConsPStack<MapEntry<Object, Object>>>empty(), 0);
@SuppressWarnings("unchecked")
@NotNull
public static <K, V> HashPMap<K, V> empty() {
return (HashPMap<K, V>) HashPMap.EMPTY;
}
@@ -51,6 +54,7 @@ public final class HashPMap<K, V> {
return null;
}
@NotNull
public HashPMap<K, V> plus(K key, V value) {
ConsPStack<MapEntry<K, V>> entries = getEntries(key.hashCode());
int size0 = entries.size();
@@ -60,6 +64,7 @@ public final class HashPMap<K, V> {
return new HashPMap<K, V>(intMap.plus(key.hashCode(), entries), size - size0 + entries.size());
}
@NotNull
public HashPMap<K, V> minus(Object key) {
ConsPStack<MapEntry<K, V>> entries = getEntries(key.hashCode());
int i = keyIndexIn(entries, key);