Skip to content

Commit 139b248

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 1fcdd0d commit 139b248

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
@@ -3919,7 +3919,8 @@ object Types {
39193919
}
39203920

39213921
override protected def derivedRefinedType(tp: RefinedType, parent: Type, info: Type) =
3922-
parent match {
3922+
if ((parent eq tp.parent) && (info eq tp.refinedInfo)) tp
3923+
else parent match {
39233924
case Range(parentLo, parentHi) =>
39243925
range(derivedRefinedType(tp, parentLo, info), derivedRefinedType(tp, parentHi, info))
39253926
case _ =>
@@ -3950,21 +3951,24 @@ object Types {
39503951
}
39513952

39523953
override protected def derivedRecType(tp: RecType, parent: Type) =
3953-
parent match {
3954+
if (parent eq tp.parent) tp
3955+
else parent match {
39543956
case Range(lo, hi) => range(tp.rebind(lo), tp.rebind(hi))
39553957
case _ => tp.rebind(parent)
39563958
}
39573959

39583960
override protected def derivedTypeAlias(tp: TypeAlias, alias: Type) =
3959-
alias match {
3961+
if (alias eq tp.alias) tp
3962+
else alias match {
39603963
case Range(lo, hi) =>
39613964
if (variance > 0) TypeBounds(lo, hi)
39623965
else range(TypeAlias(lo), TypeAlias(hi))
39633966
case _ => tp.derivedTypeAlias(alias)
39643967
}
39653968

39663969
override protected def derivedTypeBounds(tp: TypeBounds, lo: Type, hi: Type) =
3967-
if (isRange(lo) || isRange(hi))
3970+
if ((lo eq tp.lo) && (hi eq tp.hi)) tp
3971+
else if (isRange(lo) || isRange(hi))
39683972
if (variance > 0) TypeBounds(lower(lo), upper(hi))
39693973
else range(TypeBounds(upper(lo), lower(hi)), TypeBounds(lower(lo), upper(hi)))
39703974
else tp.derivedTypeBounds(lo, hi)

0 commit comments

Comments
 (0)