@@ -17,10 +17,10 @@ import scala.collection.mutable
17
17
* can hardcode them. This should, however be removed once we're using a
18
18
* different standard library.
19
19
*/
20
- class SpecializedApplyMethods extends MiniPhase with InfoTransformer {
20
+ class SpecializeApplyMethods extends MiniPhase with InfoTransformer {
21
21
import ast .tpd ._
22
22
23
- val phaseName = " specializedApplyMethods "
23
+ val phaseName = " specializeApplyMethods "
24
24
25
25
override def isEnabled (using Context ): Boolean =
26
26
! ctx.settings.scalajs.value
@@ -56,6 +56,17 @@ class SpecializedApplyMethods extends MiniPhase with InfoTransformer {
56
56
op(t1, t2, r)
57
57
}
58
58
59
+ /** Whether the name is possibly specializable?
60
+ *
61
+ * This is a micro-optimization, as name test is fast and most test would fail.
62
+ */
63
+ private def specializableName (name : Name ): Boolean =
64
+ val arity = name.functionArity
65
+ arity >= 0 && arity < 3
66
+
67
+ override def infoMayChange (sym : Symbol )(using Context ) =
68
+ specializableName(sym.name)
69
+
59
70
/** Add symbols for specialized methods to FunctionN */
60
71
override def transformInfo (tp : Type , sym : Symbol )(using Context ) = tp match {
61
72
case tp : ClassInfo if defn.isPlainFunctionClass(sym) =>
@@ -85,7 +96,7 @@ class SpecializedApplyMethods extends MiniPhase with InfoTransformer {
85
96
override def transformTemplate (tree : Template )(using Context ) = {
86
97
val cls = tree.symbol.owner.asClass
87
98
88
- if (! defn.isPlainFunctionClass(cls)) return tree
99
+ if (! specializableName(cls.name) || ! defn.isPlainFunctionClass(cls)) return tree
89
100
90
101
def synthesizeApply (names : collection.Set [TermName ]): Tree = {
91
102
val applyBuf = new mutable.ListBuffer [DefDef ]
0 commit comments