groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8271) Take/TakeRight methods on iterator needlessly calls hasNext for one too many elements
Date Thu, 27 Jul 2017 11:57:02 GMT

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

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

GitHub user MartyNeal opened a pull request:

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

    Call iterators hasNext as last when simpler checks can be done first

    Addresses https://issues.apache.org/jira/browse/GROOVY-8271

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/MartyNeal/groovy GROOVY-8271

Alternatively you can review and apply these changes as the patch at:

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

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #578
    
----
commit 16528d3b443d3c8c838c2b862e658285d211cf69
Author: Marty Neal <marty.neal@oracle.com>
Date:   2017-07-27T11:52:25Z

    Call iterators hasNext as late as possible where simpler checks can be done first

----


> 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)

Mime
View raw message