K2: Optimize ConeInferenceContext::containsInternal
We don't call it recursively on recursive types, thus 'visited' set looks irrelevant.
This commit is contained in:
committed by
Space Team
parent
9d099348ba
commit
db3b7c4021
@@ -172,35 +172,30 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
||||
|
||||
private fun KotlinTypeMarker?.containsInternal(
|
||||
predicate: (KotlinTypeMarker) -> Boolean,
|
||||
visited: HashSet<KotlinTypeMarker> = hashSetOf()
|
||||
): Boolean {
|
||||
if (this == null) return false
|
||||
if (!visited.add(this)) return false
|
||||
|
||||
if (predicate(this)) return true
|
||||
|
||||
val flexibleType = this as? ConeFlexibleType
|
||||
if (flexibleType != null
|
||||
&& (flexibleType.lowerBound.containsInternal(predicate, visited)
|
||||
|| flexibleType.upperBound.containsInternal(predicate, visited))
|
||||
&& (flexibleType.lowerBound.containsInternal(predicate) || flexibleType.upperBound.containsInternal(predicate))
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
if (this is ConeDefinitelyNotNullType
|
||||
&& this.original.containsInternal(predicate, visited)
|
||||
) {
|
||||
if (this is ConeDefinitelyNotNullType && this.original.containsInternal(predicate)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (this is ConeIntersectionType) {
|
||||
return this.intersectedTypes.any { it.containsInternal(predicate, visited) }
|
||||
return this.intersectedTypes.any { it.containsInternal(predicate) }
|
||||
}
|
||||
|
||||
repeat(argumentsCount()) { index ->
|
||||
val argument = getArgument(index)
|
||||
if (!argument.isStarProjection() && argument.getType().containsInternal(predicate, visited)) return true
|
||||
if (!argument.isStarProjection() && argument.getType().containsInternal(predicate)) return true
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user