public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Jamison Hope <jrh@theptrgroup.com>
To: "kawa@sourceware.org list" <kawa@sourceware.org>
Subject: Re: Support Iterable in for-each
Date: Fri, 10 Jan 2014 21:27:00 -0000	[thread overview]
Message-ID: <42C368E2-33FD-4BB0-A4CB-7151D9365B73@theptrgroup.com> (raw)
In-Reply-To: <52D06419.4080302@bothner.com>

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



  reply	other threads:[~2014-01-10 21:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-10 18:45 Matthieu Vachon
2014-01-10 19:24 ` Per Bothner
2014-01-10 21:04   ` Jamison Hope
2014-01-10 21:20     ` Per Bothner
2014-01-10 21:27       ` Jamison Hope [this message]
2014-01-10 21:27     ` Per Bothner
2014-01-10 21:29       ` Jamison Hope
2015-02-27  2:25   ` Per Bothner
2015-02-27 17:35     ` Jamison Hope
2015-02-27 18:22       ` Matthieu Vachon
2015-02-27 20:43       ` Per Bothner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42C368E2-33FD-4BB0-A4CB-7151D9365B73@theptrgroup.com \
    --to=jrh@theptrgroup.com \
    --cc=kawa@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).