Skip to content

Commit ad8d7e8

Browse files
committed
Performance tweak: check presence of apply
1 parent 1b1b074 commit ad8d7e8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
2525
/** Transforms the type to include decls for specialized applys */
2626
override def transformInfo(tp: Type, sym: Symbol)(using Context) = tp match {
2727
case tp: ClassInfo =>
28-
val newApplys = new mutable.ListBuffer[Symbol]
2928
val apply = tp.decls.lookup(nme.apply)
30-
3129
if (!apply.exists) return tp
3230

31+
val newApplys = new mutable.ListBuffer[Symbol]
32+
3333
var arity = 0
3434
while (arity < 3) {
3535
val func = defn.FunctionClass(arity)
@@ -72,7 +72,8 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
7272
override def transformTemplate(tree: Template)(using Context) = {
7373
val cls = tree.symbol.owner.asClass
7474

75-
if (!derivesFromFn012(cls)) return tree
75+
val apply = cls.info.decls.lookup(nme.apply)
76+
if (!apply.exists || !derivesFromFn012(cls)) return tree
7677

7778
val applyBuf = new mutable.ListBuffer[Tree]
7879
val newBody = tree.body.mapConserve {

0 commit comments

Comments
 (0)