Skip to content

Commit fc83c24

Browse files
committed
Some further optimizations on Substituters
Specialization on Subst1 reduces total unspecialized AppliedType mapOvers by ~ 15% on dotty bootstrap.
1 parent fb82b09 commit fc83c24

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,16 @@ trait Substituters { this: Context =>
192192

193193
override def mapOver2(tp: Type) = tp match {
194194
case tp: AppliedType =>
195-
def mapArgs(args: List[Type], tparams: List[ParamInfo]): List[Type] = args match {
195+
def mapArgs(args: List[Type]): List[Type] = args match {
196196
case arg :: otherArgs =>
197197
val arg1 = this(arg)
198-
val otherArgs1 = mapArgs(otherArgs, tparams.tail)
198+
val otherArgs1 = mapArgs(otherArgs)
199199
if ((arg1 eq arg) && (otherArgs1 eq otherArgs)) args
200200
else arg1 :: otherArgs1
201201
case nil =>
202202
nil
203203
}
204-
derivedAppliedType(tp, this(tp.tycon), mapArgs(tp.args, tp.typeParams))
204+
derivedAppliedType(tp, this(tp.tycon), mapArgs(tp.args))
205205
case _ =>
206206
mapOver3(tp)
207207
}
@@ -213,6 +213,22 @@ trait Substituters { this: Context =>
213213
case _: ThisType | _: BoundType => tp
214214
case _ => mapOver2(tp)
215215
}
216+
217+
override def mapOver2(tp: Type) = tp match {
218+
case tp: AppliedType =>
219+
def mapArgs(args: List[Type]): List[Type] = args match {
220+
case arg :: otherArgs =>
221+
val arg1 = this(arg)
222+
val otherArgs1 = mapArgs(otherArgs)
223+
if ((arg1 eq arg) && (otherArgs1 eq otherArgs)) args
224+
else arg1 :: otherArgs1
225+
case nil =>
226+
nil
227+
}
228+
derivedAppliedType(tp, this(tp.tycon), mapArgs(tp.args))
229+
case _ =>
230+
mapOver3(tp)
231+
}
216232
}
217233

218234
final class Subst2Map(from1: Symbol, to1: Type, from2: Symbol, to2: Type) extends DeepTypeMap {

0 commit comments

Comments
 (0)