summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2011-11-23 13:00:35 +0000
committerMartin Odersky <odersky@gmail.com>2011-11-23 13:00:35 +0000
commit579e999fbf59f540e2d6287fafa7f149ea2b0989 (patch)
treed36c9209601adfdade8171f0a0cb1fc45c6eac0a /src/library
parentf191dca582e47c8f01a030191c960e25411de0a4 (diff)
downloadscala-579e999fbf59f540e2d6287fafa7f149ea2b0989.tar.gz
scala-579e999fbf59f540e2d6287fafa7f149ea2b0989.tar.bz2
scala-579e999fbf59f540e2d6287fafa7f149ea2b0989.zip
Preparations for new version of AbstractPartial...
Preparations for new version of AbstractPartialFunctions that also does isDefinedAt correctly. Should be a new starr. Review by extempore.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/PartialFunction.scala4
-rw-r--r--src/library/scala/runtime/AbstractPartialFunction.scala8
2 files changed, 10 insertions, 2 deletions
diff --git a/src/library/scala/PartialFunction.scala b/src/library/scala/PartialFunction.scala
index ac721b88bc..254a610648 100644
--- a/src/library/scala/PartialFunction.scala
+++ b/src/library/scala/PartialFunction.scala
@@ -48,6 +48,9 @@ trait PartialFunction[-A, +B] extends (A => B) {
else that.apply(x)
}
+ def orElseFast[A1 <: A, B1 >: B](that: PartialFunction[A1, B1]) : PartialFunction[A1, B1] =
+ orElse(that)
+
/** Composes this partial function with a transformation function that
* gets applied to results of this partial function.
* @param k the transformation function
@@ -90,6 +93,7 @@ object PartialFunction {
def isDefinedAt(x: Any) = false
def apply(x: Any): Nothing = throw new MatchError(x)
override def orElse[A1, B1](that: PartialFunction[A1, B1]): PartialFunction[A1, B1] = that
+ override def orElseFast[A1, B1](that: PartialFunction[A1, B1]): PartialFunction[A1, B1] = that
override def lift = (x: Any) => None
}
def empty[A, B] : PartialFunction[A, B] = empty_pf
diff --git a/src/library/scala/runtime/AbstractPartialFunction.scala b/src/library/scala/runtime/AbstractPartialFunction.scala
index 2a45ec3671..b188cbb37d 100644
--- a/src/library/scala/runtime/AbstractPartialFunction.scala
+++ b/src/library/scala/runtime/AbstractPartialFunction.scala
@@ -32,11 +32,15 @@ abstract class AbstractPartialFunction[-T1, +R]
// Question: Need to ensure that fallBack is overwritten before any access
// Is the `synchronized` here the right thing to achieve this?
// Is there a cheaper way?
- def orElseFast[A1 <: T1, B1 >: R](that: PartialFunction[A1, B1]) : PartialFunction[A1, B1] = {
+ override def orElseFast[A1 <: T1, B1 >: R](that: PartialFunction[A1, B1]) : PartialFunction[A1, B1] = {
val result = this.clone.asInstanceOf[AbstractPartialFunction[A1, B1]]
result.synchronized {
- result.fallBack = this.fallBack orElse that
+ result.fallBack = this.fallBack orElseFast that
result
}
}
+/*
+ def isDefinedAt(x: T1): scala.Boolean = isDefinedAtCurrent(x) || fallBack.isDefinedAt(x)
+ def isDefinedAtCurrent(x: T1): scala.Boolean = false
+*/
}