Scala Programming Language
  1. Scala Programming Language
  2. SI-4802

IterableLike should override toIterator to not use toStream

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.0
    • Fix Version/s: None
    • Component/s: Misc Library
    • Labels:
      None

      Description

      (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
      

        Activity

        Hide
        Commit Message Bot added a comment -

        (extempore in r25302) Make IterableLike.toIterator more efficient

        Override TraversableLike.toIterator which uses unnecessary toStream.

        Fixes SI-4802. Contributed by Yang Zhang.

        Show
        Commit Message Bot added a comment - (extempore in r25302 ) Make IterableLike.toIterator more efficient Override TraversableLike.toIterator which uses unnecessary toStream. Fixes SI-4802 . Contributed by Yang Zhang.

          People

          • Assignee:
            Unassigned
            Reporter:
            Yang Zhang
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development