@@ -17,10 +17,10 @@ import scala.collection.mutable
1717 * can hardcode them. This should, however be removed once we're using a
1818 * different standard library.
1919 */
20- class SpecializedApplyMethods extends MiniPhase with InfoTransformer {
20+ class SpecializeApplyMethods extends MiniPhase with InfoTransformer {
2121 import ast .tpd ._
2222
23- val phaseName = " specializedApplyMethods "
23+ val phaseName = " specializeApplyMethods "
2424
2525 override def isEnabled (using Context ): Boolean =
2626 ! ctx.settings.scalajs.value
@@ -56,6 +56,17 @@ class SpecializedApplyMethods extends MiniPhase with InfoTransformer {
5656 op(t1, t2, r)
5757 }
5858
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+
5970 /** Add symbols for specialized methods to FunctionN */
6071 override def transformInfo (tp : Type , sym : Symbol )(using Context ) = tp match {
6172 case tp : ClassInfo if defn.isPlainFunctionClass(sym) =>
@@ -85,7 +96,7 @@ class SpecializedApplyMethods extends MiniPhase with InfoTransformer {
8596 override def transformTemplate (tree : Template )(using Context ) = {
8697 val cls = tree.symbol.owner.asClass
8798
88- if (! defn.isPlainFunctionClass(cls)) return tree
99+ if (! specializableName(cls.name) || ! defn.isPlainFunctionClass(cls)) return tree
89100
90101 def synthesizeApply (names : collection.Set [TermName ]): Tree = {
91102 val applyBuf = new mutable.ListBuffer [DefDef ]
0 commit comments