Skip to content

Commit aff87e0

Browse files
committed
Some opimizations on derived ops
In a commonly used derived... operation, deal with the common case that the types have not chanegd first.
1 parent ec3f7f4 commit aff87e0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3922,7 +3922,8 @@ object Types {
39223922
}
39233923

39243924
override protected def derivedRefinedType(tp: RefinedType, parent: Type, info: Type) =
3925-
parent match {
3925+
if ((parent eq tp.parent) && (info eq tp.refinedInfo)) tp
3926+
else parent match {
39263927
case Range(parentLo, parentHi) =>
39273928
range(derivedRefinedType(tp, parentLo, info), derivedRefinedType(tp, parentHi, info))
39283929
case _ =>
@@ -3953,21 +3954,24 @@ object Types {
39533954
}
39543955

39553956
override protected def derivedRecType(tp: RecType, parent: Type) =
3956-
parent match {
3957+
if (parent eq tp.parent) tp
3958+
else parent match {
39573959
case Range(lo, hi) => range(tp.rebind(lo), tp.rebind(hi))
39583960
case _ => tp.rebind(parent)
39593961
}
39603962

39613963
override protected def derivedTypeAlias(tp: TypeAlias, alias: Type) =
3962-
alias match {
3964+
if (alias eq tp.alias) tp
3965+
else alias match {
39633966
case Range(lo, hi) =>
39643967
if (variance > 0) TypeBounds(lo, hi)
39653968
else range(TypeAlias(lo), TypeAlias(hi))
39663969
case _ => tp.derivedTypeAlias(alias)
39673970
}
39683971

39693972
override protected def derivedTypeBounds(tp: TypeBounds, lo: Type, hi: Type) =
3970-
if (isRange(lo) || isRange(hi))
3973+
if ((lo eq tp.lo) && (hi eq tp.hi)) tp
3974+
else if (isRange(lo) || isRange(hi))
39713975
if (variance > 0) TypeBounds(lower(lo), upper(hi))
39723976
else range(TypeBounds(upper(lo), lower(hi)), TypeBounds(lower(lo), upper(hi)))
39733977
else tp.derivedTypeBounds(lo, hi)

0 commit comments

Comments
 (0)