Add ability to create memoized functions with custom maps
- Remove cast in ResolveSession class
This commit is contained in:
committed by
Nikolay Krasko
parent
edee61f2f5
commit
a456f9d22e
@@ -30,7 +30,6 @@ import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class LockBasedStorageManager implements StorageManager {
|
||||
|
||||
public interface ExceptionHandlingStrategy {
|
||||
ExceptionHandlingStrategy THROW = new ExceptionHandlingStrategy() {
|
||||
@NotNull
|
||||
@@ -105,7 +104,8 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected <K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(
|
||||
@Override
|
||||
public <K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(
|
||||
@NotNull Function1<? super K, ? extends V> compute,
|
||||
@NotNull ConcurrentMap<K, Object> map
|
||||
) {
|
||||
@@ -118,14 +118,9 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
return createMemoizedFunctionWithNullableValues(compute, LockBasedStorageManager.<K>createConcurrentHashMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
private static <K> ConcurrentMap<K, Object> createConcurrentHashMap() {
|
||||
// memory optimization: fewer segments and entries stored
|
||||
return new ConcurrentHashMap<K, Object>(3, 1, 2);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected <K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(
|
||||
public <K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(
|
||||
@NotNull Function1<? super K, ? extends V> compute,
|
||||
@NotNull ConcurrentMap<K, Object> map
|
||||
) {
|
||||
@@ -221,6 +216,12 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static <K> ConcurrentMap<K, Object> createConcurrentHashMap() {
|
||||
// memory optimization: fewer segments and entries stored
|
||||
return new ConcurrentHashMap<K, Object>(3, 1, 2);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected <T> RecursionDetectedResult<T> recursionDetectedDefault() {
|
||||
throw new IllegalStateException("Recursive call in a lazy value under " + this);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.storage
|
||||
|
||||
import java.util.concurrent.ConcurrentMap
|
||||
|
||||
public trait StorageManager {
|
||||
/**
|
||||
@@ -30,6 +31,10 @@ public trait StorageManager {
|
||||
|
||||
public fun createMemoizedFunctionWithNullableValues<K, V: Any>(compute: (K) -> V?): MemoizedFunctionToNullable<K, V>
|
||||
|
||||
public fun createMemoizedFunction<K, V: Any>(compute: (K) -> V, map: ConcurrentMap<K, Any>): MemoizedFunctionToNotNull<K, V>
|
||||
|
||||
public fun createMemoizedFunctionWithNullableValues<K, V: Any>(compute: (K) -> V, map: ConcurrentMap<K, Any>): MemoizedFunctionToNullable<K, V>
|
||||
|
||||
public fun createLazyValue<T: Any>(computable: () -> T): NotNullLazyValue<T>
|
||||
|
||||
public fun createRecursionTolerantLazyValue<T: Any>(computable: () -> T, onRecursiveCall: T): NotNullLazyValue<T>
|
||||
|
||||
Reference in New Issue
Block a user