diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-10-20 14:44:08 +0200 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2014-10-20 14:44:08 +0200 |
commit | 767cc4495752ac0a103d68e59fbc3b8ee27c6395 (patch) | |
tree | 6ee364d78a4608bc67025ef37b039c90c056875c | |
parent | eb15950e697eb77e52733f81c65e2d51951ad881 (diff) | |
parent | 38587c5db1d84b6aef9e85ce94d49548c7fa2c66 (diff) | |
download | scala-767cc4495752ac0a103d68e59fbc3b8ee27c6395.tar.gz scala-767cc4495752ac0a103d68e59fbc3b8ee27c6395.tar.bz2 scala-767cc4495752ac0a103d68e59fbc3b8ee27c6395.zip |
Merge pull request #4048 from lrytz/t8899
[nomerge] SI-8899 Revert "SI-8627 make Stream.filterNot non-eager"
-rw-r--r-- | bincompat-backward.whitelist.conf | 9 | ||||
-rw-r--r-- | bincompat-forward.whitelist.conf | 97 | ||||
-rw-r--r-- | src/library/scala/collection/TraversableLike.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/Stream.scala | 24 | ||||
-rw-r--r-- | test/files/run/t4332.scala | 2 | ||||
-rw-r--r-- | test/junit/scala/collection/immutable/StreamTest.scala | 18 |
6 files changed, 13 insertions, 139 deletions
diff --git a/bincompat-backward.whitelist.conf b/bincompat-backward.whitelist.conf index 6c98dc62a1..076b9bb9aa 100644 --- a/bincompat-backward.whitelist.conf +++ b/bincompat-backward.whitelist.conf @@ -186,15 +186,6 @@ filter { matchName="scala.reflect.runtime.SynchronizedOps.newNestedScope" problemName=MissingMethodProblem }, - // see github.com/scala/scala/pull/3925, SI-8627, SI-6440 - { - matchName="scala.collection.TraversableLike.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.immutable.Stream.filteredTail" - problemName=MissingMethodProblem - }, // https://github.com/scala/scala/pull/3848 -- SI-8680 { matchName="scala.collection.immutable.Stream.scala$collection$immutable$Stream$$loop$6" diff --git a/bincompat-forward.whitelist.conf b/bincompat-forward.whitelist.conf index 87a59f2d53..53401eefad 100644 --- a/bincompat-forward.whitelist.conf +++ b/bincompat-forward.whitelist.conf @@ -272,103 +272,6 @@ filter { matchName="scala.reflect.api.PredefTypeCreator" problemName=MissingClassProblem }, - // see github.com/scala/scala/pull/3925, SI-8627, SI-6440 - { - matchName="scala.collection.IterableViewLike#AbstractTransformed.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.AbstractTraversable.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.TraversableViewLike#AbstractTransformed.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.TraversableLike.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.SeqViewLike#AbstractTransformed.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.immutable.TreeSet.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.immutable.Stream.filteredTail" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.immutable.Stream.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.immutable.Stream.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.immutable.StringOps.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.immutable.TreeMap.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.concurrent.TrieMap.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.mutable.ArrayOps#ofByte.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.mutable.ArrayOps#ofLong.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.mutable.ArrayOps#ofUnit.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.mutable.ArrayOps#ofInt.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.mutable.ArrayOps#ofChar.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.mutable.ArrayOps#ofRef.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.mutable.ArrayOps#ofDouble.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.mutable.ArrayOps#ofFloat.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.mutable.ArrayOps#ofBoolean.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.mutable.ArrayOps#ofShort.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.collection.mutable.TreeSet.filterImpl" - problemName=MissingMethodProblem - }, - { - matchName="scala.reflect.io.AbstractFile.filterImpl" - problemName=MissingMethodProblem - }, // https://github.com/scala/scala/pull/3848 -- SI-8680 { matchName="scala.collection.immutable.Stream.scala$collection$immutable$Stream$$loop$6" diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index a8731a51b1..d3a7db6968 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -253,7 +253,7 @@ trait TraversableLike[+A, +Repr] extends Any b.result } - private[scala] def filterImpl(p: A => Boolean, isFlipped: Boolean): Repr = { + private def filterImpl(p: A => Boolean, isFlipped: Boolean): Repr = { val b = newBuilder for (x <- this) if (p(x) != isFlipped) b += x diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index 91a4e1c43d..714d5117d3 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -499,16 +499,6 @@ self => ) else super.flatMap(f)(bf) - override private[scala] def filterImpl(p: A => Boolean, isFlipped: Boolean): Stream[A] = { - // optimization: drop leading prefix of elems for which f returns false - // var rest = this dropWhile (!p(_)) - forget DRY principle - GC can't collect otherwise - var rest = this - while (!rest.isEmpty && p(rest.head) == isFlipped) rest = rest.tail - // private utility func to avoid `this` on stack (would be needed for the lazy arg) - if (rest.nonEmpty) Stream.filteredTail(rest, p, isFlipped) - else Stream.Empty - } - /** Returns all the elements of this `Stream` that satisfy the predicate `p` * in a new `Stream` - i.e., it is still a lazy data structure. The order of * the elements is preserved @@ -522,7 +512,15 @@ self => * // produces * }}} */ - override def filter(p: A => Boolean): Stream[A] = filterImpl(p, isFlipped = false) // This override is only left in 2.11 because of binary compatibility, see PR #3925 + override def filter(p: A => Boolean): Stream[A] = { + // optimization: drop leading prefix of elems for which f returns false + // var rest = this dropWhile (!p(_)) - forget DRY principle - GC can't collect otherwise + var rest = this + while (!rest.isEmpty && !p(rest.head)) rest = rest.tail + // private utility func to avoid `this` on stack (would be needed for the lazy arg) + if (rest.nonEmpty) Stream.filteredTail(rest, p) + else Stream.Empty + } override final def withFilter(p: A => Boolean): StreamWithFilter = new StreamWithFilter(p) @@ -1286,8 +1284,8 @@ object Stream extends SeqFactory[Stream] { else cons(start, range(start + step, end, step)) } - private[immutable] def filteredTail[A](stream: Stream[A], p: A => Boolean, isFlipped: Boolean) = { - cons(stream.head, stream.tail.filterImpl(p, isFlipped)) + private[immutable] def filteredTail[A](stream: Stream[A], p: A => Boolean) = { + cons(stream.head, stream.tail filter p) } private[immutable] def collectedTail[A, B, That](head: B, stream: Stream[A], pf: PartialFunction[A, B], bf: CanBuildFrom[Stream[A], B, That]) = { diff --git a/test/files/run/t4332.scala b/test/files/run/t4332.scala index 1c7e7d73de..5a67922911 100644 --- a/test/files/run/t4332.scala +++ b/test/files/run/t4332.scala @@ -12,7 +12,7 @@ object Test extends DirectTest { } def isExempt(sym: Symbol) = { - val exempt = Set("view", "repr", "sliceWithKnownDelta", "sliceWithKnownBound", "transform", "filterImpl") + val exempt = Set("view", "repr", "sliceWithKnownDelta", "sliceWithKnownBound", "transform") (exempt contains sym.name.decoded) } diff --git a/test/junit/scala/collection/immutable/StreamTest.scala b/test/junit/scala/collection/immutable/StreamTest.scala deleted file mode 100644 index 6dc1c79a48..0000000000 --- a/test/junit/scala/collection/immutable/StreamTest.scala +++ /dev/null @@ -1,18 +0,0 @@ -package scala.collection.immutable - -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 -import org.junit.Test -import org.junit.Assert._ - -@RunWith(classOf[JUnit4]) -class StreamTest { - - @Test - def t6727_and_t6440(): Unit = { - assertTrue(Stream.continually(()).filter(_ => true).take(2) == Seq((), ())) - assertTrue(Stream.continually(()).filterNot(_ => false).take(2) == Seq((), ())) - assertTrue(Stream(1,2,3,4,5).filter(_ < 4) == Seq(1,2,3)) - assertTrue(Stream(1,2,3,4,5).filterNot(_ > 4) == Seq(1,2,3,4)) - } -} |