Skip to content

Commit 767cc44

Browse files
committed
Merge pull request scala#4048 from lrytz/t8899
[nomerge] SI-8899 Revert "SI-8627 make Stream.filterNot non-eager"
2 parents eb15950 + 38587c5 commit 767cc44

File tree

6 files changed

+13
-139
lines changed

6 files changed

+13
-139
lines changed

bincompat-backward.whitelist.conf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,6 @@ filter {
186186
matchName="scala.reflect.runtime.SynchronizedOps.newNestedScope"
187187
problemName=MissingMethodProblem
188188
},
189-
// see github.com/scala/scala/pull/3925, SI-8627, SI-6440
190-
{
191-
matchName="scala.collection.TraversableLike.filterImpl"
192-
problemName=MissingMethodProblem
193-
},
194-
{
195-
matchName="scala.collection.immutable.Stream.filteredTail"
196-
problemName=MissingMethodProblem
197-
},
198189
// https://github.com/scala/scala/pull/3848 -- SI-8680
199190
{
200191
matchName="scala.collection.immutable.Stream.scala$collection$immutable$Stream$$loop$6"

bincompat-forward.whitelist.conf

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -272,103 +272,6 @@ filter {
272272
matchName="scala.reflect.api.PredefTypeCreator"
273273
problemName=MissingClassProblem
274274
},
275-
// see github.com/scala/scala/pull/3925, SI-8627, SI-6440
276-
{
277-
matchName="scala.collection.IterableViewLike#AbstractTransformed.filterImpl"
278-
problemName=MissingMethodProblem
279-
},
280-
{
281-
matchName="scala.collection.AbstractTraversable.filterImpl"
282-
problemName=MissingMethodProblem
283-
},
284-
{
285-
matchName="scala.collection.TraversableViewLike#AbstractTransformed.filterImpl"
286-
problemName=MissingMethodProblem
287-
},
288-
{
289-
matchName="scala.collection.TraversableLike.filterImpl"
290-
problemName=MissingMethodProblem
291-
},
292-
{
293-
matchName="scala.collection.SeqViewLike#AbstractTransformed.filterImpl"
294-
problemName=MissingMethodProblem
295-
},
296-
{
297-
matchName="scala.collection.immutable.TreeSet.filterImpl"
298-
problemName=MissingMethodProblem
299-
},
300-
{
301-
matchName="scala.collection.immutable.Stream.filteredTail"
302-
problemName=MissingMethodProblem
303-
},
304-
{
305-
matchName="scala.collection.immutable.Stream.filterImpl"
306-
problemName=MissingMethodProblem
307-
},
308-
{
309-
matchName="scala.collection.immutable.Stream.filterImpl"
310-
problemName=MissingMethodProblem
311-
},
312-
{
313-
matchName="scala.collection.immutable.StringOps.filterImpl"
314-
problemName=MissingMethodProblem
315-
},
316-
{
317-
matchName="scala.collection.immutable.TreeMap.filterImpl"
318-
problemName=MissingMethodProblem
319-
},
320-
{
321-
matchName="scala.collection.concurrent.TrieMap.filterImpl"
322-
problemName=MissingMethodProblem
323-
},
324-
{
325-
matchName="scala.collection.mutable.ArrayOps#ofByte.filterImpl"
326-
problemName=MissingMethodProblem
327-
},
328-
{
329-
matchName="scala.collection.mutable.ArrayOps#ofLong.filterImpl"
330-
problemName=MissingMethodProblem
331-
},
332-
{
333-
matchName="scala.collection.mutable.ArrayOps#ofUnit.filterImpl"
334-
problemName=MissingMethodProblem
335-
},
336-
{
337-
matchName="scala.collection.mutable.ArrayOps#ofInt.filterImpl"
338-
problemName=MissingMethodProblem
339-
},
340-
{
341-
matchName="scala.collection.mutable.ArrayOps#ofChar.filterImpl"
342-
problemName=MissingMethodProblem
343-
},
344-
{
345-
matchName="scala.collection.mutable.ArrayOps#ofRef.filterImpl"
346-
problemName=MissingMethodProblem
347-
},
348-
{
349-
matchName="scala.collection.mutable.ArrayOps#ofDouble.filterImpl"
350-
problemName=MissingMethodProblem
351-
},
352-
{
353-
matchName="scala.collection.mutable.ArrayOps#ofFloat.filterImpl"
354-
problemName=MissingMethodProblem
355-
},
356-
{
357-
matchName="scala.collection.mutable.ArrayOps#ofBoolean.filterImpl"
358-
problemName=MissingMethodProblem
359-
},
360-
{
361-
matchName="scala.collection.mutable.ArrayOps#ofShort.filterImpl"
362-
problemName=MissingMethodProblem
363-
},
364-
{
365-
matchName="scala.collection.mutable.TreeSet.filterImpl"
366-
problemName=MissingMethodProblem
367-
},
368-
{
369-
matchName="scala.reflect.io.AbstractFile.filterImpl"
370-
problemName=MissingMethodProblem
371-
},
372275
// https://github.com/scala/scala/pull/3848 -- SI-8680
373276
{
374277
matchName="scala.collection.immutable.Stream.scala$collection$immutable$Stream$$loop$6"

src/library/scala/collection/TraversableLike.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ trait TraversableLike[+A, +Repr] extends Any
253253
b.result
254254
}
255255

256-
private[scala] def filterImpl(p: A => Boolean, isFlipped: Boolean): Repr = {
256+
private def filterImpl(p: A => Boolean, isFlipped: Boolean): Repr = {
257257
val b = newBuilder
258258
for (x <- this)
259259
if (p(x) != isFlipped) b += x

src/library/scala/collection/immutable/Stream.scala

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -499,16 +499,6 @@ self =>
499499
)
500500
else super.flatMap(f)(bf)
501501

502-
override private[scala] def filterImpl(p: A => Boolean, isFlipped: Boolean): Stream[A] = {
503-
// optimization: drop leading prefix of elems for which f returns false
504-
// var rest = this dropWhile (!p(_)) - forget DRY principle - GC can't collect otherwise
505-
var rest = this
506-
while (!rest.isEmpty && p(rest.head) == isFlipped) rest = rest.tail
507-
// private utility func to avoid `this` on stack (would be needed for the lazy arg)
508-
if (rest.nonEmpty) Stream.filteredTail(rest, p, isFlipped)
509-
else Stream.Empty
510-
}
511-
512502
/** Returns all the elements of this `Stream` that satisfy the predicate `p`
513503
* in a new `Stream` - i.e., it is still a lazy data structure. The order of
514504
* the elements is preserved
@@ -522,7 +512,15 @@ self =>
522512
* // produces
523513
* }}}
524514
*/
525-
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
515+
override def filter(p: A => Boolean): Stream[A] = {
516+
// optimization: drop leading prefix of elems for which f returns false
517+
// var rest = this dropWhile (!p(_)) - forget DRY principle - GC can't collect otherwise
518+
var rest = this
519+
while (!rest.isEmpty && !p(rest.head)) rest = rest.tail
520+
// private utility func to avoid `this` on stack (would be needed for the lazy arg)
521+
if (rest.nonEmpty) Stream.filteredTail(rest, p)
522+
else Stream.Empty
523+
}
526524

527525
override final def withFilter(p: A => Boolean): StreamWithFilter = new StreamWithFilter(p)
528526

@@ -1286,8 +1284,8 @@ object Stream extends SeqFactory[Stream] {
12861284
else cons(start, range(start + step, end, step))
12871285
}
12881286

1289-
private[immutable] def filteredTail[A](stream: Stream[A], p: A => Boolean, isFlipped: Boolean) = {
1290-
cons(stream.head, stream.tail.filterImpl(p, isFlipped))
1287+
private[immutable] def filteredTail[A](stream: Stream[A], p: A => Boolean) = {
1288+
cons(stream.head, stream.tail filter p)
12911289
}
12921290

12931291
private[immutable] def collectedTail[A, B, That](head: B, stream: Stream[A], pf: PartialFunction[A, B], bf: CanBuildFrom[Stream[A], B, That]) = {

test/files/run/t4332.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Test extends DirectTest {
1212
}
1313

1414
def isExempt(sym: Symbol) = {
15-
val exempt = Set("view", "repr", "sliceWithKnownDelta", "sliceWithKnownBound", "transform", "filterImpl")
15+
val exempt = Set("view", "repr", "sliceWithKnownDelta", "sliceWithKnownBound", "transform")
1616
(exempt contains sym.name.decoded)
1717
}
1818

test/junit/scala/collection/immutable/StreamTest.scala

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)