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(
|
private fun KotlinTypeMarker?.containsInternal(
|
||||||
predicate: (KotlinTypeMarker) -> Boolean,
|
predicate: (KotlinTypeMarker) -> Boolean,
|
||||||
visited: HashSet<KotlinTypeMarker> = hashSetOf()
|
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (this == null) return false
|
if (this == null) return false
|
||||||
if (!visited.add(this)) return false
|
|
||||||
|
|
||||||
if (predicate(this)) return true
|
if (predicate(this)) return true
|
||||||
|
|
||||||
val flexibleType = this as? ConeFlexibleType
|
val flexibleType = this as? ConeFlexibleType
|
||||||
if (flexibleType != null
|
if (flexibleType != null
|
||||||
&& (flexibleType.lowerBound.containsInternal(predicate, visited)
|
&& (flexibleType.lowerBound.containsInternal(predicate) || flexibleType.upperBound.containsInternal(predicate))
|
||||||
|| flexibleType.upperBound.containsInternal(predicate, visited))
|
|
||||||
) {
|
) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (this is ConeDefinitelyNotNullType
|
if (this is ConeDefinitelyNotNullType && this.original.containsInternal(predicate)) {
|
||||||
&& this.original.containsInternal(predicate, visited)
|
|
||||||
) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this is ConeIntersectionType) {
|
if (this is ConeIntersectionType) {
|
||||||
return this.intersectedTypes.any { it.containsInternal(predicate, visited) }
|
return this.intersectedTypes.any { it.containsInternal(predicate) }
|
||||||
}
|
}
|
||||||
|
|
||||||
repeat(argumentsCount()) { index ->
|
repeat(argumentsCount()) { index ->
|
||||||
val argument = getArgument(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
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user