aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Decorators.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-03-06 22:42:15 +0100
committerMartin Odersky <odersky@gmail.com>2013-03-06 22:42:15 +0100
commit22fc38c4e062d299dc28fc429efdba4521db3651 (patch)
treee97873cacc8abbead4028ea7d2bfefb1063ec6bf /src/dotty/tools/dotc/core/Decorators.scala
parent757bf2ecc0a5dc083f21f1dc6c9d22c3795f3790 (diff)
downloaddotty-22fc38c4e062d299dc28fc429efdba4521db3651.tar.gz
dotty-22fc38c4e062d299dc28fc429efdba4521db3651.tar.bz2
dotty-22fc38c4e062d299dc28fc429efdba4521db3651.zip
Finished polishing of Types and TypeOps.
Manjor change is that splitArgs got eliminated and replaced by an optimized version of typeArgs.
Diffstat (limited to 'src/dotty/tools/dotc/core/Decorators.scala')
-rw-r--r--src/dotty/tools/dotc/core/Decorators.scala20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/core/Decorators.scala b/src/dotty/tools/dotc/core/Decorators.scala
index 87473ca33..2e2c2db0d 100644
--- a/src/dotty/tools/dotc/core/Decorators.scala
+++ b/src/dotty/tools/dotc/core/Decorators.scala
@@ -36,6 +36,11 @@ object Decorators {
* up to `MaxFilterRecursions` length.
*/
implicit class ListDecorator[T](val xs: List[T]) extends AnyVal {
+
+ /** Like `xs filter p` but returns list `xs` itself - instead of a copy -
+ * if `p` is true for all elements and `xs` is not longer
+ * than `MaxFilterRecursions`.
+ */
def filterConserve(p: T => Boolean): List[T] = {
def loop(xs: List[T], nrec: Int): List[T] = xs match {
case Nil => xs
@@ -50,6 +55,21 @@ object Decorators {
}
loop(xs, 0)
}
+
+ /** Like `(xs, ys).zipped.map(f)`, but returns list `xs` itself
+ * - instead of a copy - if function `f` maps all elements of
+ * `xs` to themselves. Also, it is required that `ys` is at least
+ * as long as `xs`.
+ */
+ def zipWithConserve[U](ys: List[U])(f: (T, U) => T): List[T] =
+ if (xs.isEmpty) xs
+ else {
+ val x1 = f(xs.head, ys.head)
+ val xs1 = xs.tail.zipWithConserve(ys.tail)(f)
+ if ((x1.asInstanceOf[AnyRef] eq xs.head.asInstanceOf[AnyRef]) &&
+ (xs1 eq xs.tail)) xs
+ else x1 :: xs1
+ }
}
/** Implements a test whether a list of strings representing phases contains