Add capacities to some ArrayList instances in project
The changed lists were visible in the profiler memory snapshot. It's unclear what this will save, but each of these lists was retaining at least several megabytes of memory
This commit is contained in:
+9
-6
@@ -41,7 +41,10 @@ import org.jetbrains.kotlin.types.Variance;
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilPackage;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.kotlin.load.java.components.TypeUsage.MEMBER_SIGNATURE_CONTRAVARIANT;
|
||||
import static org.jetbrains.kotlin.load.java.components.TypeUsage.UPPER_BOUND;
|
||||
@@ -188,8 +191,8 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
parameterDescriptors.size(), altFunDeclaration.getValueParameters().size());
|
||||
}
|
||||
|
||||
List<ValueParameterDescriptor> altParamDescriptors = new ArrayList<ValueParameterDescriptor>();
|
||||
for (int i = 0, size = parameterDescriptors.size(); i < size; i++) {
|
||||
List<ValueParameterDescriptor> altParamDescriptors = new ArrayList<ValueParameterDescriptor>(parameterDescriptors.size());
|
||||
for (int i = 0; i < parameterDescriptors.size(); i++) {
|
||||
ValueParameterDescriptor originalParameterDescriptor = parameterDescriptors.get(i);
|
||||
JetParameter annotationValueParameter = altFunDeclaration.getValueParameters().get(i);
|
||||
|
||||
@@ -231,7 +234,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
originalParameterDescriptor.declaresDefaultValue(),
|
||||
alternativeVarargElementType,
|
||||
SourceElement.NO_SOURCE
|
||||
));
|
||||
));
|
||||
}
|
||||
|
||||
altValueParameters = altParamDescriptors;
|
||||
@@ -243,9 +246,9 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
typeParameters.size(), altFunDeclaration.getTypeParameters().size());
|
||||
}
|
||||
|
||||
altTypeParameters = new ArrayList<TypeParameterDescriptor>();
|
||||
altTypeParameters = new ArrayList<TypeParameterDescriptor>(typeParameters.size());
|
||||
|
||||
for (int i = 0, size = typeParameters.size(); i < size; i++) {
|
||||
for (int i = 0; i < typeParameters.size(); i++) {
|
||||
TypeParameterDescriptor originalTypeParamDescriptor = typeParameters.get(i);
|
||||
|
||||
TypeParameterDescriptorImpl altParamDescriptor = originalToAltTypeParameters.get(originalTypeParamDescriptor);
|
||||
|
||||
+1
-1
@@ -216,7 +216,7 @@ public class SignaturesPropagationData {
|
||||
DescriptorUtils.getFqName(containingClass);
|
||||
|
||||
JetType resultReceiverType = null;
|
||||
List<ValueParameterDescriptor> resultParameters = Lists.newArrayList();
|
||||
List<ValueParameterDescriptor> resultParameters = new ArrayList<ValueParameterDescriptor>(parameters.size());
|
||||
|
||||
boolean shouldBeExtension = checkIfShouldBeExtension();
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi.Call.CallType;
|
||||
import org.jetbrains.kotlin.psi.debugText.DebugTextPackage;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -199,7 +200,7 @@ public class CallMaker {
|
||||
public static Call makeCallWithExpressions(@NotNull JetElement callElement, @NotNull ReceiverValue explicitReceiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull JetExpression calleeExpression,
|
||||
@NotNull List<JetExpression> argumentExpressions, @NotNull CallType callType) {
|
||||
List<ValueArgument> arguments = Lists.newArrayList();
|
||||
List<ValueArgument> arguments = new ArrayList<ValueArgument>(argumentExpressions.size());
|
||||
for (JetExpression argumentExpression : argumentExpressions) {
|
||||
arguments.add(makeValueArgument(argumentExpression, calleeExpression));
|
||||
}
|
||||
|
||||
+2
-1
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.createProjection
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
|
||||
// The index in the lambda is the position of the type component:
|
||||
// Example: for `A<B, C<D, E>>`, indices go as follows: `0 - A<...>, 1 - B, 2 - C<D, E>, 3 - D, 4 - E`,
|
||||
@@ -119,7 +120,7 @@ private fun JetType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers, i
|
||||
private fun List<Annotations>.compositeAnnotationsOrSingle() = when (size()) {
|
||||
0 -> error("At least one Annotations object expected")
|
||||
1 -> single()
|
||||
else -> CompositeAnnotations(this)
|
||||
else -> CompositeAnnotations(this.toReadOnlyList())
|
||||
}
|
||||
|
||||
private fun TypeComponentPosition.shouldEnhance() = this != TypeComponentPosition.INFLEXIBLE
|
||||
|
||||
@@ -739,7 +739,7 @@ public class KotlinBuiltIns {
|
||||
@NotNull List<JetType> parameterTypes,
|
||||
@NotNull JetType returnType
|
||||
) {
|
||||
List<TypeProjection> arguments = new ArrayList<TypeProjection>();
|
||||
List<TypeProjection> arguments = new ArrayList<TypeProjection>(parameterTypes.size() + (receiverType != null ? 1 : 0) + 1);
|
||||
if (receiverType != null) {
|
||||
arguments.add(defaultProjection(receiverType));
|
||||
}
|
||||
|
||||
+14
-12
@@ -302,23 +302,25 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||
@NotNull TypeSubstitutor substitutor
|
||||
) {
|
||||
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>(unsubstitutedValueParameters.size());
|
||||
for (ValueParameterDescriptor unsubstitutedValueParameter : unsubstitutedValueParameters) {
|
||||
// TODO : Lazy?
|
||||
JetType substitutedType = substitutor.substitute(unsubstitutedValueParameter.getType(), Variance.IN_VARIANCE);
|
||||
JetType varargElementType = unsubstitutedValueParameter.getVarargElementType();
|
||||
JetType substituteVarargElementType = varargElementType == null ? null : substitutor.substitute(varargElementType, Variance.IN_VARIANCE);
|
||||
JetType substituteVarargElementType =
|
||||
varargElementType == null ? null : substitutor.substitute(varargElementType, Variance.IN_VARIANCE);
|
||||
if (substitutedType == null) return null;
|
||||
result.add(new ValueParameterDescriptorImpl(
|
||||
substitutedDescriptor,
|
||||
unsubstitutedValueParameter,
|
||||
unsubstitutedValueParameter.getIndex(),
|
||||
unsubstitutedValueParameter.getAnnotations(),
|
||||
unsubstitutedValueParameter.getName(),
|
||||
substitutedType,
|
||||
unsubstitutedValueParameter.declaresDefaultValue(),
|
||||
substituteVarargElementType,
|
||||
SourceElement.NO_SOURCE
|
||||
result.add(
|
||||
new ValueParameterDescriptorImpl(
|
||||
substitutedDescriptor,
|
||||
unsubstitutedValueParameter,
|
||||
unsubstitutedValueParameter.getIndex(),
|
||||
unsubstitutedValueParameter.getAnnotations(),
|
||||
unsubstitutedValueParameter.getName(),
|
||||
substitutedType,
|
||||
unsubstitutedValueParameter.declaresDefaultValue(),
|
||||
substituteVarargElementType,
|
||||
SourceElement.NO_SOURCE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -212,12 +212,11 @@ public class CommonSupertypes {
|
||||
}
|
||||
|
||||
List<TypeParameterDescriptor> parameters = constructor.getParameters();
|
||||
List<TypeProjection> newProjections = new ArrayList<TypeProjection>();
|
||||
for (int i = 0, parametersSize = parameters.size(); i < parametersSize; i++) {
|
||||
TypeParameterDescriptor parameterDescriptor = parameters.get(i);
|
||||
List<TypeProjection> newProjections = new ArrayList<TypeProjection>(parameters.size());
|
||||
for (TypeParameterDescriptor parameterDescriptor : parameters) {
|
||||
Set<TypeProjection> typeProjections = new HashSet<TypeProjection>();
|
||||
for (JetType type : types) {
|
||||
typeProjections.add(type.getArguments().get(i));
|
||||
typeProjections.add(type.getArguments().get(parameterDescriptor.getIndex()));
|
||||
}
|
||||
newProjections.add(computeSupertypeProjection(parameterDescriptor, typeProjections, recursionDepth, maxDepth));
|
||||
}
|
||||
|
||||
@@ -425,12 +425,12 @@ public class TypeUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<TypeProjection> getDefaultTypeProjections(List<TypeParameterDescriptor> parameters) {
|
||||
List<TypeProjection> result = new ArrayList<TypeProjection>();
|
||||
public static List<TypeProjection> getDefaultTypeProjections(@NotNull List<TypeParameterDescriptor> parameters) {
|
||||
List<TypeProjection> result = new ArrayList<TypeProjection>(parameters.size());
|
||||
for (TypeParameterDescriptor parameterDescriptor : parameters) {
|
||||
result.add(new TypeProjectionImpl(parameterDescriptor.getDefaultType()));
|
||||
}
|
||||
return result;
|
||||
return UtilsPackage.toReadOnlyList(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user