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.
This commit is contained in:
@@ -18,6 +18,8 @@ import org.jetbrains.kotlin.fir.typeContext
|
|||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.types.model.CaptureStatus
|
import org.jetbrains.kotlin.types.model.CaptureStatus
|
||||||
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
|
import org.jetbrains.kotlin.utils.SmartSet
|
||||||
|
|
||||||
abstract class SupertypeSupplier {
|
abstract class SupertypeSupplier {
|
||||||
abstract fun forClass(firClass: FirClass<*>): List<ConeClassLikeType>
|
abstract fun forClass(firClass: FirClass<*>): List<ConeClassLikeType>
|
||||||
@@ -37,13 +39,13 @@ fun lookupSuperTypes(
|
|||||||
supertypeSupplier: SupertypeSupplier = SupertypeSupplier.Default,
|
supertypeSupplier: SupertypeSupplier = SupertypeSupplier.Default,
|
||||||
substituteTypes: Boolean = false
|
substituteTypes: Boolean = false
|
||||||
): List<ConeClassLikeType> {
|
): List<ConeClassLikeType> {
|
||||||
return mutableListOf<ConeClassLikeType>().also {
|
return SmartList<ConeClassLikeType>().also {
|
||||||
klass.symbol.collectSuperTypes(it, mutableSetOf(), deep, lookupInterfaces, substituteTypes, useSiteSession, supertypeSupplier)
|
klass.symbol.collectSuperTypes(it, SmartSet.create(), deep, lookupInterfaces, substituteTypes, useSiteSession, supertypeSupplier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FirClass<*>.isThereLoopInSupertypes(session: FirSession): Boolean {
|
fun FirClass<*>.isThereLoopInSupertypes(session: FirSession): Boolean {
|
||||||
val visitedSymbols: MutableSet<FirClassifierSymbol<*>> = mutableSetOf()
|
val visitedSymbols: MutableSet<FirClassifierSymbol<*>> = SmartSet.create()
|
||||||
val inProcess: MutableSet<FirClassifierSymbol<*>> = mutableSetOf()
|
val inProcess: MutableSet<FirClassifierSymbol<*>> = mutableSetOf()
|
||||||
|
|
||||||
var isThereLoop = false
|
var isThereLoop = false
|
||||||
@@ -82,8 +84,8 @@ fun lookupSuperTypes(
|
|||||||
useSiteSession: FirSession,
|
useSiteSession: FirSession,
|
||||||
supertypeSupplier: SupertypeSupplier = SupertypeSupplier.Default
|
supertypeSupplier: SupertypeSupplier = SupertypeSupplier.Default
|
||||||
): List<ConeClassLikeType> {
|
): List<ConeClassLikeType> {
|
||||||
return mutableListOf<ConeClassLikeType>().also {
|
return SmartList<ConeClassLikeType>().also {
|
||||||
symbol.collectSuperTypes(it, mutableSetOf(), deep, lookupInterfaces, false, useSiteSession, supertypeSupplier)
|
symbol.collectSuperTypes(it, SmartSet.create(), deep, lookupInterfaces, false, useSiteSession, supertypeSupplier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +182,7 @@ private fun FirClassifierSymbol<*>.collectSuperTypes(
|
|||||||
superClassTypes.forEach {
|
superClassTypes.forEach {
|
||||||
if (it !is ConeClassErrorType) {
|
if (it !is ConeClassErrorType) {
|
||||||
if (substituteSuperTypes) {
|
if (substituteSuperTypes) {
|
||||||
val substitutedTypes = mutableListOf<ConeClassLikeType>()
|
val substitutedTypes = SmartList<ConeClassLikeType>()
|
||||||
it.lookupTag.toSymbol(useSiteSession)?.collectSuperTypes(
|
it.lookupTag.toSymbol(useSiteSession)?.collectSuperTypes(
|
||||||
substitutedTypes,
|
substitutedTypes,
|
||||||
visitedSymbols,
|
visitedSymbols,
|
||||||
|
|||||||
Reference in New Issue
Block a user