You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2017/08/01 05:35:00 UTC
[jira] [Resolved] (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:all-tabpanel ]
Paul King resolved GROOVY-8271.
-------------------------------
Resolution: Fixed
Assignee: Paul King
Fix Version/s: 2.4.13
Fix applied - thanks!
> 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
> Assignee: Paul King
> Priority: Minor
> Fix For: 2.4.13
>
>
> 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)