Weakly retained memoized functions moved out of util.runtime
This commit is contained in:
committed by
Alexander Udalov
parent
5ebbe0d772
commit
0765e89b19
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.storage;
|
||||
|
||||
import com.intellij.util.containers.ConcurrentWeakValueHashMap;
|
||||
import jet.Function0;
|
||||
import jet.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -50,24 +49,30 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(
|
||||
@NotNull Function1<K, V> compute, @NotNull ReferenceKind valuesReferenceKind
|
||||
public <K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(@NotNull Function1<K, V> compute) {
|
||||
return createMemoizedFunction(compute, new ConcurrentHashMap<K, Object>());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected <K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(
|
||||
@NotNull Function1<K, V> compute,
|
||||
@NotNull ConcurrentMap<K, Object> map
|
||||
) {
|
||||
ConcurrentMap<K, Object> map = createConcurrentMap(valuesReferenceKind);
|
||||
return new MapBasedMemoizedFunctionToNotNull<K, V>(lock, map, compute);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(
|
||||
@NotNull Function1<K, V> compute, @NotNull ReferenceKind valuesReferenceKind
|
||||
) {
|
||||
ConcurrentMap<K, Object> map = createConcurrentMap(valuesReferenceKind);
|
||||
return new MapBasedMemoizedFunction<K, V>(lock, map, compute);
|
||||
public <K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(@NotNull Function1<K, V> compute) {
|
||||
return createMemoizedFunctionWithNullableValues(compute, new ConcurrentHashMap<K, Object>());
|
||||
}
|
||||
|
||||
private static <K, V> ConcurrentMap<K, V> createConcurrentMap(ReferenceKind referenceKind) {
|
||||
return (referenceKind == ReferenceKind.WEAK) ? new ConcurrentWeakValueHashMap<K, V>() : new ConcurrentHashMap<K, V>();
|
||||
@NotNull
|
||||
protected <K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(
|
||||
@NotNull Function1<K, V> compute,
|
||||
@NotNull ConcurrentMap<K, Object> map
|
||||
) {
|
||||
return new MapBasedMemoizedFunction<K, V>(lock, map, compute);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -30,9 +30,9 @@ public interface StorageManager {
|
||||
* NOTE: if compute() has side-effects the WEAK reference kind is dangerous: the side-effects will be repeated if
|
||||
*/
|
||||
@NotNull
|
||||
<K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(@NotNull Function1<K, V> compute, @NotNull ReferenceKind valuesReferenceKind);
|
||||
<K, V> MemoizedFunctionToNotNull<K, V> createMemoizedFunction(@NotNull Function1<K, V> compute);
|
||||
@NotNull
|
||||
<K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(@NotNull Function1<K, V> compute, @NotNull ReferenceKind valuesReferenceKind);
|
||||
<K, V> MemoizedFunctionToNullable<K, V> createMemoizedFunctionWithNullableValues(@NotNull Function1<K, V> compute);
|
||||
|
||||
@NotNull
|
||||
<T> NotNullLazyValue<T> createLazyValue(@NotNull Function0<T> computable);
|
||||
@@ -69,9 +69,4 @@ public interface StorageManager {
|
||||
<T> NullableLazyValue<T> createNullableLazyValueWithPostCompute(@NotNull Function0<T> computable, @NotNull Function1<T, Void> postCompute);
|
||||
|
||||
<T> T compute(@NotNull Function0<T> computable);
|
||||
|
||||
enum ReferenceKind {
|
||||
STRONG,
|
||||
WEAK
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user