Add explicit fast path in TypeCheckerContext::anySupertype
This commit is contained in:
@@ -70,6 +70,8 @@ open class TypeCheckerContext(val errorTypeEqualsToAnything: Boolean, val allowe
|
||||
predicate: (SimpleType) -> Boolean,
|
||||
supertypesPolicy: (SimpleType) -> SupertypesPolicy
|
||||
): Boolean {
|
||||
if (predicate(start)) return true
|
||||
|
||||
initialize()
|
||||
|
||||
val deque = supertypesDeque!!
|
||||
@@ -81,18 +83,17 @@ open class TypeCheckerContext(val errorTypeEqualsToAnything: Boolean, val allowe
|
||||
error("Too many supertypes for type: $start. Supertypes = ${visitedSupertypes.joinToString()}")
|
||||
}
|
||||
val current = deque.pop()
|
||||
|
||||
if (!visitedSupertypes.add(current)) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (predicate(current)) {
|
||||
clear()
|
||||
return true
|
||||
}
|
||||
if (!visitedSupertypes.add(current)) continue
|
||||
|
||||
val policy = supertypesPolicy(current).takeIf { it != SupertypesPolicy.None } ?: continue
|
||||
for (supertype in current.constructor.supertypes) deque.add(policy.transformType(supertype))
|
||||
for (supertype in current.constructor.supertypes) {
|
||||
val newType = policy.transformType(supertype)
|
||||
if (predicate(newType)) {
|
||||
clear()
|
||||
return true
|
||||
}
|
||||
deque.add(newType)
|
||||
}
|
||||
}
|
||||
|
||||
clear()
|
||||
@@ -134,4 +135,4 @@ open class TypeCheckerContext(val errorTypeEqualsToAnything: Boolean, val allowe
|
||||
}
|
||||
|
||||
val UnwrappedType.isAllowedTypeVariable: Boolean get() = allowedTypeVariable && constructor is NewTypeVariableConstructor
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user