diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-11-09 16:50:37 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-01-19 14:27:31 +1000 |
commit | 634c454dbd546e2f3db6321b4047b3cebd2f899a (patch) | |
tree | 2d474c55abcc1eb012a1abe1602bcadfccb9c5f1 /src/main/scala/scala/async | |
parent | e28832dcda3c3f40425ca71dde8aa9c1a1e424d3 (diff) | |
download | scala-async-634c454dbd546e2f3db6321b4047b3cebd2f899a.tar.gz scala-async-634c454dbd546e2f3db6321b4047b3cebd2f899a.tar.bz2 scala-async-634c454dbd546e2f3db6321b4047b3cebd2f899a.zip |
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.
Diffstat (limited to 'src/main/scala/scala/async')
-rw-r--r-- | src/main/scala/scala/async/internal/AsyncTransform.scala | 10 |
1 files changed, 9 insertions, 1 deletions
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) |