[Commonizer] Improve performance of deserialization

^KT-48288
This commit is contained in:
sebastian.sellmair
2021-09-17 09:58:36 +02:00
committed by Space
parent 16bf5f3df3
commit fa2577dda8
2 changed files with 12 additions and 23 deletions
@@ -36,28 +36,20 @@ private data class CirAnnotationInternedImpl(
override val constantValueArguments: Map<CirName, CirConstantValue>,
override val annotationValueArguments: Map<CirName, CirAnnotation>
) : CirAnnotation {
// See also org.jetbrains.kotlin.types.KotlinType.cachedHashCode
private var cachedHashCode = 0
private fun computeHashCode() = hashCode(type)
private var hashCode = hashCode(type)
.appendHashCode(constantValueArguments)
.appendHashCode(annotationValueArguments)
override fun hashCode(): Int {
var currentHashCode = cachedHashCode
if (currentHashCode != 0) return currentHashCode
currentHashCode = computeHashCode()
cachedHashCode = currentHashCode
return currentHashCode
}
override fun hashCode(): Int = hashCode
override fun equals(other: Any?): Boolean {
if (other === this) return true
return other is CirAnnotation
&& type == other.type
&& constantValueArguments == other.constantValueArguments
&& annotationValueArguments == other.annotationValueArguments
if (other is CirAnnotationInternedImpl && other.hashCode != this.hashCode) return false
if (other !is CirAnnotation) return false
if (other.type != this.type) return false
if (other.constantValueArguments != this.constantValueArguments) return false
if (other.annotationValueArguments != this.annotationValueArguments) return false
return true
}
}
@@ -24,20 +24,17 @@ internal class CirTreePackageDeserializer(
): CirTreePackage {
val pkg = CirPackage.create(packageName)
val properties = fragments.asSequence().mapNotNull { it.pkg }
val properties = fragments.mapNotNull { it.pkg }
.flatMap { it.properties }
.mapNotNull { property -> propertyDeserializer(property, null, typeResolver) }
.toList()
val functions = fragments.asSequence().mapNotNull { it.pkg }
val functions = fragments.mapNotNull { it.pkg }
.flatMap { it.functions }
.mapNotNull { function -> functionDeserializer(function, null, typeResolver) }
.toList()
val typeAliases = fragments.asSequence().mapNotNull { it.pkg }
val typeAliases = fragments.mapNotNull { it.pkg }
.flatMap { it.typeAliases }
.mapNotNull { typeAlias -> typeAliasDeserializer(typeAlias, pkg.packageName, typeResolver) }
.toList()
.map { typeAlias -> typeAliasDeserializer(typeAlias, pkg.packageName, typeResolver) }
val classes = ClassesToProcess()
.apply { fragments.forEach { fragment -> addClassesFromFragment(fragment) } }