This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Support Iterable in for-each


On Jan 10, 2014, at 4:20 PM, Per Bothner <per@bothner.com> wrote:

> On 01/10/2014 01:04 PM, Jamison Hope wrote:
>> On Jan 10, 2014, at 2:24 PM, Per Bothner <per@bothner.com> wrote:
> 
>>> * It is possible to come up with some iteration protocol that
>>> at least avoids object allocation for Kawa lists and vectors, and
>>> perhaps falls back to Iterator in the generic case.  However, I haven't
>>> figured out a way to do so without 3 method calls per iteration step.
>>> (The problem is for a list the "state" variable is an object (a pair);
>>> for a vector it is an index.  To avoid heap allocation the state
>>> needs to be one or more local variables.  Thus for each step you may need
>>> to update an object and/or an int, plus you need to extract the next
>>> value.)
>> 
>> I count two: Iterator#hasNext() and Iterator#next().  What's the third
>> method call?  Just the invocation of the passed procedure?
> 
> You missed the requirement "some iteration protocol that at least avoids
> object allocation for Kawa lists and vectors".  Using Iterator#hasNext(
> and Iterator#next() implies that you have allocated an Iterator.  It's not
> per-step, but it is per-iteration.  Perhaps I should worry less about it.

I was assuming that the existing for-each and vector-for-each would remain,
so Kawa lists and vectors would avoid this entirely.  The path that treats
the sequence as an Iterable would be the last resort.

--
Jamison Hope
The PTR Group
www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]