You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/08/01 05:31:02 UTC

[jira] [Commented] (GROOVY-8271) Take/TakeRight methods on iterator needlessly calls hasNext for one too many elements

    [ https://issues.apache.org/jira/browse/GROOVY-8271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16108394#comment-16108394 ] 

ASF GitHub Bot commented on GROOVY-8271:
----------------------------------------

Github user asfgit closed the pull request at:

    https://github.com/apache/groovy/pull/578


> Take/TakeRight methods on iterator needlessly calls hasNext for one too many elements
> -------------------------------------------------------------------------------------
>
>                 Key: GROOVY-8271
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8271
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 2.4.12
>            Reporter: Marty Neal
>            Priority: Minor
>
> 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();}}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)