Use SmartList for storing annotations in binary classes

Looks like in the most cases there are <= 1 annotations
in real declarations
This commit is contained in:
Denis Zharkov
2017-05-17 14:56:39 +03:00
parent 36ab31f2f7
commit c7e6f200da
4 changed files with 16 additions and 5 deletions
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter
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.org.objectweb.asm.Type
import java.text.CharacterIterator
import java.text.StringCharacterIterator
@@ -45,7 +46,7 @@ class BinaryClassSignatureParser(globalContext: ClassifierResolutionContext) {
return emptyList()
}
val typeParameters = ContainerUtil.newArrayList<JavaTypeParameter>()
val typeParameters = ContainerUtil.newSmartList<JavaTypeParameter>()
signature.next()
while (signature.current() != '>') {
typeParameters.add(parseTypeParameter(signature, context))
@@ -148,7 +149,10 @@ class BinaryClassSignatureParser(globalContext: ClassifierResolutionContext) {
if (canonicalName.toString() == "java/lang/Object") return JAVA_LANG_OBJECT_CLASSIFIER_TYPE
return PlainJavaClassifierType({ context.resolveByInternalName(canonicalName.toString()) }, argumentGroups.reversed().flatten())
return PlainJavaClassifierType(
{ context.resolveByInternalName(canonicalName.toString()) },
argumentGroups.reversed().flattenTo(ContainerUtil.newSmartList())
)
}
private fun parseClassOrTypeVariableElement(signature: CharacterIterator, context: ClassifierResolutionContext): JavaType {
@@ -41,7 +41,7 @@ class BinaryJavaClass(
) : ClassVisitor(ASM_API_VERSION_FOR_CLASS_READING), VirtualFileBoundJavaClass, BinaryJavaModifierListOwner, MapBasedJavaAnnotationOwner {
lateinit var myInternalName: String
override val annotations: MutableCollection<JavaAnnotation> = mutableListOf()
override val annotations: MutableCollection<JavaAnnotation> = ContainerUtil.newSmartList()
override lateinit var typeParameters: List<JavaTypeParameter>
override lateinit var supertypes: Collection<JavaClassifierType>
override val methods = arrayListOf<JavaMethod>()
@@ -36,7 +36,7 @@ abstract class BinaryJavaMethodBase(
) : JavaMember, MapBasedJavaAnnotationOwner, BinaryJavaModifierListOwner {
override val annotationsByFqName by buildLazyValueForMap()
override val annotations: Collection<JavaAnnotation> = mutableListOf()
override val annotations: Collection<JavaAnnotation> = ContainerUtil.newSmartList()
companion object {
private class MethodInfo(
@@ -130,4 +130,11 @@ inline fun <T> measureTimeMillisWithResult(block: () -> T) : Pair<Long, T> {
val start = System.currentTimeMillis()
val result = block()
return Pair(System.currentTimeMillis() - start, result)
}
}
public fun <T> Iterable<Iterable<T>>.flattenTo(c: MutableList<T>): List<T> {
for (element in this) {
c.addAll(element)
}
return c
}