Call compactIfPossible where it's possible in BinaryJava*

It helps to avoid retaining a lot of redundant empty SmartList's
instances
This commit is contained in:
Denis Zharkov
2017-05-25 16:39:16 +03:00
parent e2ce285ec3
commit d7cee95d95
3 changed files with 15 additions and 8 deletions
@@ -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<JavaTypeParameter>()
val typeParameters = ContainerUtil.newArrayList<JavaTypeParameter>()
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()
)
}
@@ -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<JavaValueParameter>()
val parameterList = ContainerUtil.newArrayList<JavaValueParameter>()
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<JavaType>
var paramTypes: List<JavaType>
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()