Skip to content

Commit 1b1b074

Browse files
committed
Performance tweak
1 parent b177728 commit 1b1b074

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,28 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
2020
!ctx.settings.scalajs.value
2121

2222
override def infoMayChange(sym: Symbol)(using Context): Boolean =
23-
!sym.is(Flags.Package) && sym.isDefinedInCurrentRun
23+
!sym.is(Flags.Package) && sym.isClass && sym.isDefinedInCurrentRun
2424

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 =>
2828
val newApplys = new mutable.ListBuffer[Symbol]
29+
val apply = tp.decls.lookup(nme.apply)
30+
31+
if (!apply.exists) return tp
2932

3033
var arity = 0
3134
while (arity < 3) {
3235
val func = defn.FunctionClass(arity)
3336
if (tp.derivesFrom(func)) {
34-
var specializedMethodName: Name = null
35-
def isSpecializable =
36-
val paramTypes = tp.cls.typeRef.baseType(func).argInfos
37-
val argTypes = paramTypes.init
38-
val retType = paramTypes.last
39-
defn.isSpecializableFunction(sym.asClass, argTypes, retType) && {
40-
specializedMethodName = nme.apply.specializedFunction(retType, argTypes)
41-
true
42-
}
37+
val paramTypes = tp.cls.typeRef.baseType(func).argInfos
38+
val argTypes = paramTypes.init
39+
val retType = paramTypes.last
40+
41+
val isSpecializable = defn.isSpecializableFunction(sym.asClass, argTypes, retType)
4342

44-
val apply = tp.decls.lookup(nme.apply)
45-
if (apply.exists && isSpecializable) {
43+
if (isSpecializable) {
44+
val specializedMethodName: Name = nme.apply.specializedFunction(retType, argTypes)
4645
val applySpecialized = newSymbol(
4746
sym,
4847
specializedMethodName,
@@ -71,7 +70,7 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
7170
* in the template body.
7271
*/
7372
override def transformTemplate(tree: Template)(using Context) = {
74-
val cls = tree.symbol.enclosingClass.asClass
73+
val cls = tree.symbol.owner.asClass
7574

7675
if (!derivesFromFn012(cls)) return tree
7776

0 commit comments

Comments
 (0)