From d7cee95d95dc3145dd269afbec97f446dd7d3a78 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Thu, 25 May 2017 16:39:16 +0300 Subject: [PATCH] Call compactIfPossible where it's possible in BinaryJava* It helps to avoid retaining a lot of redundant empty SmartList's instances --- .../impl/classFiles/BinaryClassSignatureParser.kt | 7 ++++--- .../load/java/structure/impl/classFiles/Methods.kt | 14 ++++++++++---- .../src/org/jetbrains/kotlin/utils/addToStdlib.kt | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryClassSignatureParser.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryClassSignatureParser.kt index f6f2db3db00..2fe283dc324 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryClassSignatureParser.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/BinaryClassSignatureParser.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.utils.addToStdlib.flattenTo +import org.jetbrains.kotlin.utils.compactIfPossible import org.jetbrains.org.objectweb.asm.Type import java.text.CharacterIterator import java.text.StringCharacterIterator @@ -46,13 +47,13 @@ class BinaryClassSignatureParser(globalContext: ClassifierResolutionContext) { return emptyList() } - val typeParameters = ContainerUtil.newSmartList() + val typeParameters = ContainerUtil.newArrayList() signature.next() while (signature.current() != '>') { typeParameters.add(parseTypeParameter(signature, context)) } signature.next() - return typeParameters + return typeParameters.compactIfPossible() } private fun parseTypeParameter(signature: CharacterIterator, context: ClassifierResolutionContext): JavaTypeParameter { @@ -151,7 +152,7 @@ class BinaryClassSignatureParser(globalContext: ClassifierResolutionContext) { return PlainJavaClassifierType( { context.resolveByInternalName(canonicalName.toString()) }, - argumentGroups.reversed().flattenTo(ContainerUtil.newSmartList()) + argumentGroups.reversed().flattenTo(arrayListOf()).compactIfPossible() ) } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Methods.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Methods.kt index 56651b87cad..b6f1c481fbd 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Methods.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Methods.kt @@ -21,6 +21,7 @@ import com.intellij.util.containers.ContainerUtil import org.jetbrains.kotlin.load.java.structure.* import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.SpecialNames +import org.jetbrains.kotlin.utils.compactIfPossible import org.jetbrains.org.objectweb.asm.MethodVisitor import org.jetbrains.org.objectweb.asm.Opcodes import org.jetbrains.org.objectweb.asm.Type @@ -79,7 +80,7 @@ abstract class BinaryJavaMethodBase( } val parameterTypes = info.valueParameterTypes - val parameterList = ContainerUtil.newSmartList() + val parameterList = ContainerUtil.newArrayList() val paramCount = parameterTypes.size for (i in 0..paramCount - 1) { val type = parameterTypes[i] @@ -93,7 +94,10 @@ abstract class BinaryJavaMethodBase( BinaryJavaConstructor(access, containingClass, parameterList, info.typeParameters) else BinaryJavaMethod( - access, containingClass, parameterList, info.typeParameters, Name.identifier(name), info.returnType + access, containingClass, + parameterList.compactIfPossible(), + info.typeParameters, + Name.identifier(name), info.returnType ) val paramIgnoreCount = when { @@ -126,16 +130,18 @@ abstract class BinaryJavaMethodBase( if (iterator.current() != '(') throw ClsFormatException() iterator.next() - val paramTypes: List + var paramTypes: List if (iterator.current() == ')') { paramTypes = emptyList() } else { - paramTypes = ContainerUtil.newSmartList() + paramTypes = ContainerUtil.newArrayList() while (iterator.current() != ')' && iterator.current() != CharacterIterator.DONE) { paramTypes.add(signatureParser.parseTypeString(iterator, context)) } if (iterator.current() != ')') throw ClsFormatException() + + paramTypes = (paramTypes as ArrayList).compactIfPossible() } iterator.next() diff --git a/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt b/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt index 31cba469b9a..be639c80350 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt @@ -132,7 +132,7 @@ inline fun measureTimeMillisWithResult(block: () -> T) : Pair { return Pair(System.currentTimeMillis() - start, result) } -public fun Iterable>.flattenTo(c: MutableList): List { +fun > Iterable>.flattenTo(c: C): C { for (element in this) { c.addAll(element) }