Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8271

Take/TakeRight methods on iterator needlessly calls hasNext for one too many elements

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.12
    • 2.4.13
    • groovy-jdk
    • None

    Description

      I expect the TakeIterator to only call the hasNext() method for the delegate a maximum of N times where N is the number of elements to take. If the iterator represents some expensive operations, or an unexhausted infinite stream that has exactly N elements available, the TakeIterator will block waiting for the Nth+1 element only to return N of them.

      In short, change the TakeIterator's hasNext function from

      return delegate.hasNext() && num > 0;
      to

      return num > 0 && delegate.hasNext();

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              cheeseheadtothe Marty Neal
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: