From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7139 invoked by alias); 10 Jan 2014 21:27:00 -0000 Mailing-List: contact kawa-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: kawa-owner@sourceware.org Received: (qmail 7127 invoked by uid 89); 10 Jan 2014 21:26:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail.theptrgroup.com Received: from mail.theptrgroup.com (HELO mail.theptrgroup.com) (71.178.251.9) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Jan 2014 21:26:59 +0000 Received: from [10.11.21.58] (unknown [10.11.21.58]) by mail.theptrgroup.com (Postfix) with ESMTPS id 7F9A1E0936 for ; Fri, 10 Jan 2014 16:26:57 -0500 (EST) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: Support Iterable in for-each From: Jamison Hope In-Reply-To: <52D06419.4080302@bothner.com> Date: Fri, 10 Jan 2014 21:27:00 -0000 Content-Transfer-Encoding: 7bit Message-Id: <42C368E2-33FD-4BB0-A4CB-7151D9365B73@theptrgroup.com> References: <52D048D4.2080803@bothner.com> <596354A4-C4B3-40B6-BCED-2FCF1CB1B9C5@theptrgroup.com> <52D06419.4080302@bothner.com> To: "kawa@sourceware.org list" X-IsSubscribed: yes X-SW-Source: 2014-q1/txt/msg00007.txt.bz2 On Jan 10, 2014, at 4:20 PM, Per Bothner wrote: > On 01/10/2014 01:04 PM, Jamison Hope wrote: >> On Jan 10, 2014, at 2:24 PM, Per Bothner 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