Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
abreslav committed Feb 11, 2013
1 parent 3e0ead4 commit a3667d1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
Expand Up @@ -36,7 +36,7 @@
import java.util.Set;

import static org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils.safeNameForLazyResolve;
import static org.jetbrains.jet.lang.resolve.lazy.StorageManager.MemoizationMode.STRONG;
import static org.jetbrains.jet.lang.resolve.lazy.StorageManager.ReferenceKind.STRONG;

public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, DP extends DeclarationProvider> implements JetScope {
protected final ResolveSession resolveSession;
Expand Down
Expand Up @@ -70,7 +70,7 @@ public Index compute() {
public PackageMemberDeclarationProvider fun(FqName fqName) {
return createPackageMemberDeclarationProvider(fqName);
}
}, StorageManager.MemoizationMode.STRONG);
}, StorageManager.ReferenceKind.STRONG);
}

@NotNull
Expand Down
Expand Up @@ -45,7 +45,7 @@ public LazyPackageMemberScope(@NotNull ResolveSession resolveSession,
public NamespaceDescriptor fun(Name name) {
return createPackageDescriptor(name);
}
}, StorageManager.MemoizationMode.STRONG);
}, StorageManager.ReferenceKind.STRONG);
}

@Override
Expand Down
Expand Up @@ -32,7 +32,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import static org.jetbrains.jet.lang.resolve.lazy.StorageManager.MemoizationMode.WEAK;
import static org.jetbrains.jet.lang.resolve.lazy.StorageManager.ReferenceKind.WEAK;

public class LockBasedStorageManager implements StorageManager {

Expand All @@ -45,9 +45,9 @@ public String toString() {

@NotNull
@Override
public <K, V> Function<K, V> createMemoizedFunction(@NotNull final Function<K, V> compute, @NotNull final MemoizationMode modeForValues) {
public <K, V> Function<K, V> createMemoizedFunction(@NotNull final Function<K, V> compute, @NotNull final ReferenceKind valuesReferenceKind) {
return new Function<K, V>() {
private final ConcurrentMap<K, V> cache = createConcurrentMap(modeForValues);
private final ConcurrentMap<K, V> cache = createConcurrentMap(valuesReferenceKind);

@Override
public V fun(@NotNull final K input) {
Expand All @@ -72,10 +72,10 @@ public V fun(@NotNull final K input) {
@NotNull
@Override
public <K, V> Function<K, V> createMemoizedFunctionWithNullableValues(
@NotNull final Function<K, V> compute, @NotNull final MemoizationMode modeForValues
@NotNull final Function<K, V> compute, @NotNull final ReferenceKind valuesReferenceKind
) {
return new Function<K, V>() {
private final ConcurrentMap<K, LazyValue<V>> cache = createConcurrentMap(modeForValues);
private final ConcurrentMap<K, LazyValue<V>> cache = createConcurrentMap(valuesReferenceKind);

@Override
public V fun(@NotNull final K input) {
Expand All @@ -97,8 +97,8 @@ public V compute() {
};
}

private static <K, V> ConcurrentMap<K, V> createConcurrentMap(MemoizationMode mode) {
return (mode == WEAK) ? new ConcurrentWeakValueHashMap<K, V>() : new ConcurrentHashMap<K, V>();
private static <K, V> ConcurrentMap<K, V> createConcurrentMap(ReferenceKind referenceKind) {
return (referenceKind == WEAK) ? new ConcurrentWeakValueHashMap<K, V>() : new ConcurrentHashMap<K, V>();
}

@NotNull
Expand Down
Expand Up @@ -34,7 +34,7 @@
import java.util.Collection;
import java.util.List;

import static org.jetbrains.jet.lang.resolve.lazy.StorageManager.MemoizationMode.WEAK;
import static org.jetbrains.jet.lang.resolve.lazy.StorageManager.ReferenceKind.WEAK;

public class ScopeProvider {
private final ResolveSession resolveSession;
Expand Down
Expand Up @@ -26,12 +26,15 @@ public interface StorageManager {
/**
* Given a function compute: K -> V create a memoized version of it that computes a value only once for each key
* @param compute the function to be memoized
* @param modeForValues how to store teh memoized values
* @param valuesReferenceKind how to store teh memoized values
*
* NOTE: if compute() has side-effects the WEAK reference kind is dangerous: the side-effects will be repeated if
* the value gets collected and then re-computed
*/
@NotNull
<K, V> Function<K, V> createMemoizedFunction(@NotNull Function<K, V> compute, @NotNull MemoizationMode modeForValues);
<K, V> Function<K, V> createMemoizedFunction(@NotNull Function<K, V> compute, @NotNull ReferenceKind valuesReferenceKind);
@NotNull
<K, V> Function<K, V> createMemoizedFunctionWithNullableValues(@NotNull Function<K, V> compute, @NotNull MemoizationMode modeForValues);
<K, V> Function<K, V> createMemoizedFunctionWithNullableValues(@NotNull Function<K, V> compute, @NotNull ReferenceKind valuesReferenceKind);

@NotNull
<T> LazyValue<T> createLazyValue(@NotNull Computable<T> computable);
Expand All @@ -56,7 +59,7 @@ public interface StorageManager {
@NotNull
BindingTrace createSafeTrace(@NotNull BindingTrace originalTrace);

enum MemoizationMode {
enum ReferenceKind {
STRONG,
WEAK
}
Expand Down

0 comments on commit a3667d1

Please sign in to comment.