From 634c454dbd546e2f3db6321b4047b3cebd2f899a Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Mon, 9 Nov 2015 16:50:37 +1000 Subject: Use AbstractFunction as a base class to emit leaner code Avoids mixing in all the specialized apply variants. We could go further and create an base class for all state machines, but that would require scala-async to be on the runtime classpath, which currently isn't a requirement. For now, I'm keeping it this way. --- src/main/scala/scala/async/internal/AsyncTransform.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/scala/scala/async/internal/AsyncTransform.scala b/src/main/scala/scala/async/internal/AsyncTransform.scala index fa0eec7..2f45034 100644 --- a/src/main/scala/scala/async/internal/AsyncTransform.scala +++ b/src/main/scala/scala/async/internal/AsyncTransform.scala @@ -49,7 +49,15 @@ trait AsyncTransform { List(emptyConstructor, stateVar) ++ resultAndAccessors ++ List(execContextValDef) ++ List(applyDefDefDummyBody, apply0DefDef) } - val tryToUnit = appliedType(definitions.FunctionClass(1), futureSystemOps.tryType[Any], typeOf[Unit]) + val customParents = futureSystemOps.stateMachineClassParents + val tycon = if (customParents.exists(!_.typeSymbol.asClass.isTrait)) { + // prefer extending a class to reduce the class file size of the state machine. + symbolOf[scala.runtime.AbstractFunction1[Any, Any]] + } else { + // ... unless a custom future system already extends some class + symbolOf[scala.Function1[Any, Any]] + } + val tryToUnit = appliedType(tycon, futureSystemOps.tryType[Any], typeOf[Unit]) val template = Template((futureSystemOps.stateMachineClassParents ::: List(tryToUnit, typeOf[() => Unit])).map(TypeTree(_)), emptyValDef, body) val t = ClassDef(NoMods, name.stateMachineT, Nil, template) -- cgit v1.2.3