From 7d09097aac4a3f0e802fdbc539014ec6018efd79 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 31 Oct 2013 11:52:14 +0100 Subject: Collections: remove redundant calls to .seq Students of Scala's history might recall that at introduction of parallel collections, GenIterable et al were *not* added; instead the parallel collections inherited from the existing interfaces. This of course was an invitation to widespread disaster as any existing code that foreach-ed over a collection might now experience unwanted concurrency. The first attempt to fix this was to add the `.seq` method to convert a parallel colleciton to a sequential one. This was added in e579152f732, and call sites in the standard library with side-effecting foreach calls were changed to use that. But this was (rightly) deemed inadequate, as we could hardly expect people to change existing code or remember to do this in new code. So later, in 3de96153e5b, GenIterable was sprouted, and parallel collections were re-parented. This commit removes residual needless calls to .seq when the static type of the receiver is already a plain Iterable, which are no-ops. --- src/library/scala/collection/TraversableOnce.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/library/scala/collection/TraversableOnce.scala') diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index 2fdad0f8f9..26af32046c 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -97,7 +97,7 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] { // for internal use protected[this] def reversed = { var elems: List[A] = Nil - self.seq foreach (elems ::= _) + self foreach (elems ::= _) elems } @@ -140,7 +140,7 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] { def foldLeft[B](z: B)(op: (B, A) => B): B = { var result = z - this.seq foreach (x => result = op(result, x)) + this foreach (x => result = op(result, x)) result } -- cgit v1.2.3