Skip to content

Commit 9bf34e1

Browse files
dzharkovSpace Team
authored andcommitted
FE: Optimize ConeFlexibleType's hashCode/equals for trivial types
1 parent ef43a9e commit 9bf34e1

File tree

1 file changed

+9
-1
lines changed
  • compiler/fir/cones/src/org/jetbrains/kotlin/fir/types

1 file changed

+9
-1
lines changed

compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypes.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,22 @@ open class ConeFlexibleType(
143143
if (other !is ConeFlexibleType) return false
144144

145145
if (lowerBound != other.lowerBound) return false
146+
147+
if (isTrivial && other.isTrivial) return true
148+
146149
if (upperBound != other.upperBound) return false
147150

148151
return true
149152
}
150153

151154
final override fun hashCode(): Int {
152155
var result = lowerBound.hashCode()
153-
result = 31 * result + upperBound.hashCode()
156+
// We don't use `upperBound.hashCode()` because it might lead to performance loss for trivial types.
157+
// While doing something like `31 * lowerBoundResult + Boolean.hashCode(true/* markedNullable */)`
158+
// to replicate `upperBound.hashCode()` behavior seems too fragile.
159+
// But we want the result was different from just lowerBound's one,
160+
// so we add a beautiful though random prime number.
161+
result = 31 * result + 2999
154162
return result
155163
}
156164
}

0 commit comments

Comments
 (0)