From 7ed35e5c2b36f8ca776174e066b4a823b0a4ebed Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Sat, 13 Mar 2021 16:47:55 +0100 Subject: [PATCH] FIR: Introduce smart containers in supertypes search assuming that we may have quite many searches resulting in a single supertypes, smart containers here reduce allocations. --- .../jetbrains/kotlin/fir/resolve/SupertypeUtils.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt index 8d21e25afb6..887e249ced6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SupertypeUtils.kt @@ -18,6 +18,8 @@ import org.jetbrains.kotlin.fir.typeContext import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.types.model.CaptureStatus +import org.jetbrains.kotlin.utils.SmartList +import org.jetbrains.kotlin.utils.SmartSet abstract class SupertypeSupplier { abstract fun forClass(firClass: FirClass<*>): List @@ -37,13 +39,13 @@ fun lookupSuperTypes( supertypeSupplier: SupertypeSupplier = SupertypeSupplier.Default, substituteTypes: Boolean = false ): List { - return mutableListOf().also { - klass.symbol.collectSuperTypes(it, mutableSetOf(), deep, lookupInterfaces, substituteTypes, useSiteSession, supertypeSupplier) + return SmartList().also { + klass.symbol.collectSuperTypes(it, SmartSet.create(), deep, lookupInterfaces, substituteTypes, useSiteSession, supertypeSupplier) } } fun FirClass<*>.isThereLoopInSupertypes(session: FirSession): Boolean { - val visitedSymbols: MutableSet> = mutableSetOf() + val visitedSymbols: MutableSet> = SmartSet.create() val inProcess: MutableSet> = mutableSetOf() var isThereLoop = false @@ -82,8 +84,8 @@ fun lookupSuperTypes( useSiteSession: FirSession, supertypeSupplier: SupertypeSupplier = SupertypeSupplier.Default ): List { - return mutableListOf().also { - symbol.collectSuperTypes(it, mutableSetOf(), deep, lookupInterfaces, false, useSiteSession, supertypeSupplier) + return SmartList().also { + symbol.collectSuperTypes(it, SmartSet.create(), deep, lookupInterfaces, false, useSiteSession, supertypeSupplier) } } @@ -180,7 +182,7 @@ private fun FirClassifierSymbol<*>.collectSuperTypes( superClassTypes.forEach { if (it !is ConeClassErrorType) { if (substituteSuperTypes) { - val substitutedTypes = mutableListOf() + val substitutedTypes = SmartList() it.lookupTag.toSymbol(useSiteSession)?.collectSuperTypes( substitutedTypes, visitedSymbols,