@@ -56,38 +56,30 @@ class SpecializeApplyMethods 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
59
override def infoMayChange (sym : Symbol )(using Context ) =
68
- specializableName(sym.name)
60
+ sym == defn.SpecializableFunctions (0 )
61
+ || sym == defn.SpecializableFunctions (1 )
62
+ || sym == defn.SpecializableFunctions (2 )
69
63
70
64
/** Add symbols for specialized methods to FunctionN */
71
65
override def transformInfo (tp : Type , sym : Symbol )(using Context ) = tp match {
72
- case tp : ClassInfo if defn.isPlainFunctionClass(sym) =>
73
- sym.name.functionArity match {
74
- case 0 =>
66
+ case tp : ClassInfo =>
67
+ if sym == defn.SpecializableFunctions (0 ) then
75
68
val scope = tp.decls.cloneScope
76
69
specFun0 { r => scope.enter(specApplySymbol(sym, Nil , r)) }
77
70
tp.derivedClassInfo(decls = scope)
78
71
79
- case 1 =>
72
+ else if sym == defn. SpecializableFunctions ( 1 ) then
80
73
val scope = tp.decls.cloneScope
81
74
specFun1 { (t1, r) => scope.enter(specApplySymbol(sym, List (t1), r)) }
82
75
tp.derivedClassInfo(decls = scope)
83
76
84
- case 2 =>
77
+ else if sym == defn. SpecializableFunctions ( 2 ) then
85
78
val scope = tp.decls.cloneScope
86
79
specFun2 { (t1, t2, r) => scope.enter(specApplySymbol(sym, List (t1, t2), r)) }
87
80
tp.derivedClassInfo(decls = scope)
88
81
89
- case _ => tp
90
- }
82
+ else tp
91
83
92
84
case _ => tp
93
85
}
@@ -96,8 +88,6 @@ class SpecializeApplyMethods extends MiniPhase with InfoTransformer {
96
88
override def transformTemplate (tree : Template )(using Context ) = {
97
89
val cls = tree.symbol.owner.asClass
98
90
99
- if (! specializableName(cls.name) || ! defn.isPlainFunctionClass(cls)) return tree
100
-
101
91
def synthesizeApply (names : collection.Set [TermName ]): Tree = {
102
92
val applyBuf = new mutable.ListBuffer [DefDef ]
103
93
names.foreach { name =>
@@ -116,18 +106,13 @@ class SpecializeApplyMethods extends MiniPhase with InfoTransformer {
116
106
cpy.Template (tree)(body = tree.body ++ applyBuf)
117
107
}
118
108
119
- cls.name.functionArity match {
120
- case 0 =>
121
- synthesizeApply(defn.Function0SpecializedApplyNames )
122
-
123
- case 1 =>
124
- synthesizeApply(defn.Function1SpecializedApplyNames )
125
-
126
- case 2 =>
127
- synthesizeApply(defn.Function2SpecializedApplyNames )
128
-
129
- case _ =>
130
- tree
131
- }
109
+ if cls == defn.SpecializableFunctions (0 ) then
110
+ synthesizeApply(defn.Function0SpecializedApplyNames )
111
+ else if cls == defn.SpecializableFunctions (1 ) then
112
+ synthesizeApply(defn.Function1SpecializedApplyNames )
113
+ else if cls == defn.SpecializableFunctions (2 ) then
114
+ synthesizeApply(defn.Function2SpecializedApplyNames )
115
+ else
116
+ tree
132
117
}
133
118
}
0 commit comments