Memory optimization. Do not put sets into caches
This commit is contained in:
+12
-12
@@ -51,8 +51,8 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
|
|
||||||
private final MemoizedFunctionToNotNull<Name, List<ClassDescriptor>> classDescriptors;
|
private final MemoizedFunctionToNotNull<Name, List<ClassDescriptor>> classDescriptors;
|
||||||
|
|
||||||
private final MemoizedFunctionToNotNull<Name, Set<FunctionDescriptor>> functionDescriptors;
|
private final MemoizedFunctionToNotNull<Name, Collection<FunctionDescriptor>> functionDescriptors;
|
||||||
private final MemoizedFunctionToNotNull<Name, Set<VariableDescriptor>> propertyDescriptors;
|
private final MemoizedFunctionToNotNull<Name, Collection<VariableDescriptor>> propertyDescriptors;
|
||||||
|
|
||||||
private final NotNullLazyValue<Collection<DeclarationDescriptor>> descriptorsFromDeclaredElements;
|
private final NotNullLazyValue<Collection<DeclarationDescriptor>> descriptorsFromDeclaredElements;
|
||||||
private final NotNullLazyValue<Collection<DeclarationDescriptor>> extraDescriptors;
|
private final NotNullLazyValue<Collection<DeclarationDescriptor>> extraDescriptors;
|
||||||
@@ -76,15 +76,15 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.functionDescriptors = storageManager.createMemoizedFunction(new Function1<Name, Set<FunctionDescriptor>>() {
|
this.functionDescriptors = storageManager.createMemoizedFunction(new Function1<Name, Collection<FunctionDescriptor>>() {
|
||||||
@Override
|
@Override
|
||||||
public Set<FunctionDescriptor> invoke(Name name) {
|
public Collection<FunctionDescriptor> invoke(Name name) {
|
||||||
return doGetFunctions(name);
|
return doGetFunctions(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.propertyDescriptors = storageManager.createMemoizedFunction(new Function1<Name, Set<VariableDescriptor>>() {
|
this.propertyDescriptors = storageManager.createMemoizedFunction(new Function1<Name, Collection<VariableDescriptor>>() {
|
||||||
@Override
|
@Override
|
||||||
public Set<VariableDescriptor> invoke(Name name) {
|
public Collection<VariableDescriptor> invoke(Name name) {
|
||||||
return doGetProperties(name);
|
return doGetProperties(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -131,12 +131,12 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
||||||
return functionDescriptors.invoke(name);
|
return functionDescriptors.invoke(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Set<FunctionDescriptor> doGetFunctions(@NotNull Name name) {
|
private Collection<FunctionDescriptor> doGetFunctions(@NotNull Name name) {
|
||||||
Set<FunctionDescriptor> result = Sets.newLinkedHashSet();
|
Set<FunctionDescriptor> result = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
Collection<JetNamedFunction> declarations = declarationProvider.getFunctionDeclarations(name);
|
Collection<JetNamedFunction> declarations = declarationProvider.getFunctionDeclarations(name);
|
||||||
@@ -154,7 +154,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
|
|
||||||
getNonDeclaredFunctions(name, result);
|
getNonDeclaredFunctions(name, result);
|
||||||
|
|
||||||
return UtilsPackage.toReadOnlySet(result);
|
return UtilsPackage.toReadOnlyList(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -164,12 +164,12 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<VariableDescriptor> getProperties(@NotNull Name name) {
|
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||||
return propertyDescriptors.invoke(name);
|
return propertyDescriptors.invoke(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Set<VariableDescriptor> doGetProperties(@NotNull Name name) {
|
public Collection<VariableDescriptor> doGetProperties(@NotNull Name name) {
|
||||||
Set<VariableDescriptor> result = Sets.newLinkedHashSet();
|
Set<VariableDescriptor> result = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
Collection<JetProperty> declarations = declarationProvider.getPropertyDeclarations(name);
|
Collection<JetProperty> declarations = declarationProvider.getPropertyDeclarations(name);
|
||||||
@@ -190,7 +190,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
|
|
||||||
getNonDeclaredProperties(name, result);
|
getNonDeclaredProperties(name, result);
|
||||||
|
|
||||||
return UtilsPackage.toReadOnlySet(result);
|
return UtilsPackage.toReadOnlyList(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void getNonDeclaredProperties(@NotNull Name name, @NotNull Set<VariableDescriptor> result);
|
protected abstract void getNonDeclaredProperties(@NotNull Name name, @NotNull Set<VariableDescriptor> result);
|
||||||
|
|||||||
+8
-8
@@ -135,9 +135,9 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
||||||
// TODO: this should be handled by lazy function descriptors
|
// TODO: this should be handled by lazy function descriptors
|
||||||
Set<FunctionDescriptor> functions = super.getFunctions(name);
|
Collection<FunctionDescriptor> functions = super.getFunctions(name);
|
||||||
resolveUnknownVisibilitiesForMembers(functions);
|
resolveUnknownVisibilitiesForMembers(functions);
|
||||||
return functions;
|
return functions;
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
|||||||
if (parameter.getType().isError()) continue;
|
if (parameter.getType().isError()) continue;
|
||||||
if (!primaryConstructorParameters.get(parameter.getIndex()).hasValOrVarNode()) continue;
|
if (!primaryConstructorParameters.get(parameter.getIndex()).hasValOrVarNode()) continue;
|
||||||
|
|
||||||
Set<VariableDescriptor> properties = getProperties(parameter.getName());
|
Collection<VariableDescriptor> properties = getProperties(parameter.getName());
|
||||||
if (properties.isEmpty()) continue;
|
if (properties.isEmpty()) continue;
|
||||||
|
|
||||||
assert properties.size() == 1 :
|
assert properties.size() == 1 :
|
||||||
@@ -205,14 +205,14 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Set<VariableDescriptor> getProperties(@NotNull Name name) {
|
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||||
// TODO: this should be handled by lazy property descriptors
|
// TODO: this should be handled by lazy property descriptors
|
||||||
Set<VariableDescriptor> properties = super.getProperties(name);
|
Collection<VariableDescriptor> properties = super.getProperties(name);
|
||||||
resolveUnknownVisibilitiesForMembers((Set) properties);
|
resolveUnknownVisibilitiesForMembers((Collection) properties);
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolveUnknownVisibilitiesForMembers(@NotNull Set<? extends CallableMemberDescriptor> descriptors) {
|
private void resolveUnknownVisibilitiesForMembers(@NotNull Collection<? extends CallableMemberDescriptor> descriptors) {
|
||||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||||
if (descriptor.getKind() != FAKE_OVERRIDE && descriptor.getKind() != DELEGATION) {
|
if (descriptor.getKind() != FAKE_OVERRIDE && descriptor.getKind() != DELEGATION) {
|
||||||
OverridingUtil.resolveUnknownVisibilityForMember(descriptor, OverrideResolver.createCannotInferVisibilityReporter(trace));
|
OverridingUtil.resolveUnknownVisibilityForMember(descriptor, OverrideResolver.createCannotInferVisibilityReporter(trace));
|
||||||
@@ -328,7 +328,7 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
|||||||
int n = 1;
|
int n = 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
Name componentName = DataClassUtilsPackage.createComponentName(n);
|
Name componentName = DataClassUtilsPackage.createComponentName(n);
|
||||||
Set<FunctionDescriptor> functions = getFunctions(componentName);
|
Collection<FunctionDescriptor> functions = getFunctions(componentName);
|
||||||
if (functions.isEmpty()) break;
|
if (functions.isEmpty()) break;
|
||||||
|
|
||||||
result.addAll(functions);
|
result.addAll(functions);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.util.ArrayList
|
|||||||
import java.util.HashMap
|
import java.util.HashMap
|
||||||
import java.util.HashSet
|
import java.util.HashSet
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
|
import java.util.LinkedHashSet
|
||||||
|
|
||||||
public fun <K, V> Stream<V>.valuesToMap(key: (V) -> K): Map<K, V> {
|
public fun <K, V> Stream<V>.valuesToMap(key: (V) -> K): Map<K, V> {
|
||||||
val map = LinkedHashMap<K, V>()
|
val map = LinkedHashMap<K, V>()
|
||||||
@@ -98,6 +99,3 @@ public fun <E> newHashSetWithExpectedSize(expectedSize: Int): HashSet<E> {
|
|||||||
|
|
||||||
public fun <T> Collection<T>.toReadOnlyList(): List<T> =
|
public fun <T> Collection<T>.toReadOnlyList(): List<T> =
|
||||||
if (isEmpty()) Collections.emptyList() else ArrayList(this)
|
if (isEmpty()) Collections.emptyList() else ArrayList(this)
|
||||||
|
|
||||||
public fun <T> Collection<T>.toReadOnlySet(): Set<T> =
|
|
||||||
if (isEmpty()) Collections.emptySet() else HashSet(this)
|
|
||||||
Reference in New Issue
Block a user