Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IterableLike should override toIterator to not use toStream #4802

Closed
scabug opened this issue Jul 14, 2011 · 2 comments
Closed

IterableLike should override toIterator to not use toStream #4802

scabug opened this issue Jul 14, 2011 · 2 comments

Comments

@scabug
Copy link

scabug commented Jul 14, 2011

(Gen)TraversableOnce.toIterator is overridden in TraversableLike as {toStream.iterator}. But for Iterables, this should just be {iterator}.

Should be easy win, but as a motivator example, the following is inefficient (due to the intermediate Stream):

def izip[A,B](xs: TraversableOnce[A], ys: TraversableOnce[B]) =
  xs.toIterator zip ys.toIterator

and must be expanded to:

def izip[A,B](xs: Iterable[A], ys: Iterable[B]) =
  xs.iterator zip ys.iterator
def izip[A,B](xs: Iterator[A], ys: Iterable[B]) =
  xs zip ys.iterator
def izip[A,B](xs: Iterable[A], ys: Iterator[B]) =
  xs.iterator zip ys
def izip[A,B](xs: Iterator[A], ys: Iterator[B]) =
  xs zip ys
// .. and more needed to handle Traversables as well
@scabug
Copy link
Author

scabug commented Jul 14, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4802?orig=1
Reporter: Yang Zhang (yaaang)
Affected Versions: 2.9.0

@scabug
Copy link
Author

scabug commented Jul 16, 2011

Commit Message Bot (anonymous) said:
(extempore in r25302) Make IterableLike.toIterator more efficient

Override TraversableLike.toIterator which uses unnecessary toStream.

Fixes #4802. Contributed by Yang Zhang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant