From 5fb68614da51c601e354d13ae123820b355594d0 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 19 Oct 2011 21:31:55 +0000 Subject: AbstractPartialFunction. Contributed by Todd Vierling with minor mods by extempore. This is an obvious extension of AbstractFunctionN which I had some issue making work at the time. Sounds kind of pitiful given that the compiler patch is about two lines, but let's all agree to believe it was a different world then. This example program is impacted as follows: class A { def f: PartialFunction[Any, Int] = { case x: String => 1 } def g: PartialFunction[Any, Int] = f orElse { case x: List[_] => 2 } def h: PartialFunction[Any, Int] = g orElse { case x: Set[_] => 3 } } Before: 34943 bytes of bytecode After: 4217 bytes of bytecode A mere 88% reduction in size. "'Tis but a trifle!" Closes SI-5096, SI-5097. --- src/actors/scala/actors/Actor.scala | 2 +- src/actors/scala/actors/Future.scala | 2 +- src/actors/scala/actors/Reactor.scala | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src/actors') diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala index ba4d90f0b3..b2cd69e914 100644 --- a/src/actors/scala/actors/Actor.scala +++ b/src/actors/scala/actors/Actor.scala @@ -246,7 +246,7 @@ object Actor extends Combinators { rawSelf.react(new RecursiveProxyHandler(rawSelf, f)) private class RecursiveProxyHandler(a: ReplyReactor, f: PartialFunction[Any, Unit]) - extends PartialFunction[Any, Unit] { + extends scala.runtime.AbstractPartialFunction[Any, Unit] { def isDefinedAt(m: Any): Boolean = true // events are immediately removed from the mailbox def apply(m: Any) { diff --git a/src/actors/scala/actors/Future.scala b/src/actors/scala/actors/Future.scala index 735c13190b..4de73507fb 100644 --- a/src/actors/scala/actors/Future.scala +++ b/src/actors/scala/actors/Future.scala @@ -200,7 +200,7 @@ object Futures { Actor.timer.schedule(timerTask, timeout) def awaitWith(partFuns: Seq[PartialFunction[Any, Pair[Int, Any]]]) { - val reaction: PartialFunction[Any, Unit] = new PartialFunction[Any, Unit] { + val reaction: PartialFunction[Any, Unit] = new scala.runtime.AbstractPartialFunction[Any, Unit] { def isDefinedAt(msg: Any) = msg match { case TIMEOUT => true case _ => partFuns exists (_ isDefinedAt msg) diff --git a/src/actors/scala/actors/Reactor.scala b/src/actors/scala/actors/Reactor.scala index 507c18d04e..8f0492f149 100644 --- a/src/actors/scala/actors/Reactor.scala +++ b/src/actors/scala/actors/Reactor.scala @@ -38,11 +38,10 @@ private[actors] object Reactor { } } - val waitingForNone = new PartialFunction[Any, Unit] { + val waitingForNone: PartialFunction[Any, Unit] = new scala.runtime.AbstractPartialFunction[Any, Unit] { def isDefinedAt(x: Any) = false def apply(x: Any) {} } - } /** -- cgit v1.2.3