Merge stored empty lists and sets to singe object
This commit is contained in:
+7
-6
@@ -39,6 +39,7 @@ import org.jetbrains.jet.storage.MemoizedFunctionToNotNull;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
import org.jetbrains.jet.utils.Printer;
|
||||
import org.jetbrains.jet.utils.UtilsPackage;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -106,7 +107,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
private List<ClassDescriptor> resolveClassDescriptor(@NotNull final Name name) {
|
||||
Collection<JetClassLikeInfo> classOrObjectDeclarations = declarationProvider.getClassOrObjectDeclarations(name);
|
||||
|
||||
return ContainerUtil.mapNotNull(classOrObjectDeclarations, new Function<JetClassLikeInfo, ClassDescriptor>() {
|
||||
return UtilsPackage.toReadOnlyList(ContainerUtil.mapNotNull(classOrObjectDeclarations, new Function<JetClassLikeInfo, ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor fun(JetClassLikeInfo classLikeInfo) {
|
||||
// SCRIPT: Creating a script class
|
||||
@@ -115,7 +116,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
}
|
||||
return new LazyClassDescriptor(resolveSession, thisDescriptor, name, classLikeInfo);
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -153,7 +154,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
|
||||
getNonDeclaredFunctions(name, result);
|
||||
|
||||
return result;
|
||||
return UtilsPackage.toReadOnlySet(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -189,7 +190,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
|
||||
getNonDeclaredProperties(name, result);
|
||||
|
||||
return result;
|
||||
return UtilsPackage.toReadOnlySet(result);
|
||||
}
|
||||
|
||||
protected abstract void getNonDeclaredProperties(@NotNull Name name, @NotNull Set<VariableDescriptor> result);
|
||||
@@ -252,8 +253,8 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
throw new IllegalArgumentException("Unsupported declaration kind: " + declaration);
|
||||
}
|
||||
}
|
||||
result.trimToSize();
|
||||
return result;
|
||||
|
||||
return UtilsPackage.toReadOnlyList(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+3
-3
@@ -36,6 +36,7 @@ import org.jetbrains.jet.lang.types.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.storage.NullableLazyValue;
|
||||
import org.jetbrains.jet.utils.UtilsPackage;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -299,7 +300,7 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
||||
@Override
|
||||
@NotNull
|
||||
protected Collection<DeclarationDescriptor> computeExtraDescriptors() {
|
||||
ArrayList<DeclarationDescriptor> result = new ArrayList<DeclarationDescriptor>();
|
||||
List<DeclarationDescriptor> result = new ArrayList<DeclarationDescriptor>();
|
||||
for (JetType supertype : thisDescriptor.getTypeConstructor().getSupertypes()) {
|
||||
for (DeclarationDescriptor descriptor : supertype.getMemberScope().getAllDescriptors()) {
|
||||
if (descriptor instanceof FunctionDescriptor) {
|
||||
@@ -314,8 +315,7 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
||||
|
||||
addDataClassMethods(result);
|
||||
|
||||
result.trimToSize();
|
||||
return result;
|
||||
return UtilsPackage.toReadOnlyList(result);
|
||||
}
|
||||
|
||||
private void addDataClassMethods(@NotNull Collection<DeclarationDescriptor> result) {
|
||||
|
||||
+3
-2
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.resolve.lazy.data.JetScriptInfo;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.ClassMemberDeclarationProvider;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
||||
import org.jetbrains.jet.utils.UtilsPackage;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
@@ -61,13 +62,13 @@ public class LazyScriptClassMemberScope extends LazyClassMemberScope {
|
||||
@NotNull
|
||||
@Override
|
||||
protected Collection<DeclarationDescriptor> computeExtraDescriptors() {
|
||||
return KotlinPackage.plus(
|
||||
return UtilsPackage.toReadOnlyList(KotlinPackage.plus(
|
||||
super.computeExtraDescriptors(),
|
||||
KotlinPackage.plus(
|
||||
getProperties(Name.identifier(ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME)),
|
||||
getPropertiesForScriptParameters()
|
||||
)
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
private Collection<VariableDescriptor> getPropertiesForScriptParameters() {
|
||||
|
||||
+4
-5
@@ -100,7 +100,7 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList(functions)
|
||||
functions.toReadOnlyList()
|
||||
}
|
||||
|
||||
data class MethodSignatureData(
|
||||
@@ -237,8 +237,7 @@ public abstract class LazyJavaMemberScope(
|
||||
|
||||
computeNonDeclaredProperties(name, properties)
|
||||
|
||||
properties.trimToSize()
|
||||
properties
|
||||
properties.toReadOnlyList()
|
||||
}
|
||||
|
||||
private fun resolveProperty(field: JavaField): PropertyDescriptor {
|
||||
@@ -303,7 +302,7 @@ public abstract class LazyJavaMemberScope(
|
||||
override fun getOwnDeclaredDescriptors() = getAllDescriptors()
|
||||
override fun getAllDescriptors() = _allDescriptors()
|
||||
|
||||
private fun computeAllDescriptors(): MutableCollection<DeclarationDescriptor> {
|
||||
private fun computeAllDescriptors(): List<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>()
|
||||
|
||||
for (name in getAllClassNames()) {
|
||||
@@ -324,7 +323,7 @@ public abstract class LazyJavaMemberScope(
|
||||
|
||||
addExtraDescriptors(result)
|
||||
|
||||
return ArrayList(result)
|
||||
return result.toReadOnlyList()
|
||||
}
|
||||
|
||||
protected open fun addExtraDescriptors(result: MutableSet<DeclarationDescriptor>) {
|
||||
|
||||
+4
-3
@@ -31,6 +31,7 @@ import org.jetbrains.jet.storage.MemoizedFunctionToNotNull;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
import org.jetbrains.jet.utils.Printer;
|
||||
import org.jetbrains.jet.utils.UtilsPackage;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -135,7 +136,7 @@ public abstract class DeserializedMemberScope implements JetScope {
|
||||
private Collection<FunctionDescriptor> computeFunctions(@NotNull Name name) {
|
||||
Collection<FunctionDescriptor> descriptors = computeMembersByName(name, FUNCTION);
|
||||
computeNonDeclaredFunctions(name, descriptors);
|
||||
return new ArrayList<FunctionDescriptor>(descriptors);
|
||||
return UtilsPackage.toReadOnlyList(descriptors);
|
||||
}
|
||||
|
||||
protected void computeNonDeclaredFunctions(@NotNull Name name, @NotNull Collection<FunctionDescriptor> functions) {
|
||||
@@ -152,7 +153,7 @@ public abstract class DeserializedMemberScope implements JetScope {
|
||||
Collection<PropertyDescriptor> descriptors = computeMembersByName(name, PROPERTY);
|
||||
computeNonDeclaredProperties(name, descriptors);
|
||||
//noinspection unchecked
|
||||
return new ArrayList<VariableDescriptor>((Collection) descriptors);
|
||||
return UtilsPackage.<VariableDescriptor>toReadOnlyList(descriptors);
|
||||
}
|
||||
|
||||
protected void computeNonDeclaredProperties(@NotNull Name name, @NotNull Collection<PropertyDescriptor> descriptors) {
|
||||
@@ -211,7 +212,7 @@ public abstract class DeserializedMemberScope implements JetScope {
|
||||
|
||||
addAllClassDescriptors(result);
|
||||
|
||||
return result;
|
||||
return UtilsPackage.toReadOnlyList(result);
|
||||
}
|
||||
|
||||
protected abstract void addNonDeclaredDescriptors(@NotNull Collection<DeclarationDescriptor> result);
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.LinkedHashMap
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import java.util.HashSet
|
||||
import java.util.Collections
|
||||
|
||||
public fun <K, V> Stream<V>.valuesToMap(key: (V) -> K): Map<K, V> {
|
||||
val map = LinkedHashMap<K, V>()
|
||||
@@ -94,3 +95,9 @@ public fun <K, V> newHashMapWithExpectedSize(expectedSize: Int): HashMap<K, V> {
|
||||
public fun <E> newHashSetWithExpectedSize(expectedSize: Int): HashSet<E> {
|
||||
return HashSet(if (expectedSize < 3) 3 else expectedSize + expectedSize / 3 + 1)
|
||||
}
|
||||
|
||||
public fun <T> Collection<T>.toReadOnlyList(): List<T> =
|
||||
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