From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3831 invoked by alias); 10 Jan 2014 21:20:47 -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 3822 invoked by uid 89); 10 Jan 2014 21:20:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: aibo.runbox.com Received: from aibo.runbox.com (HELO aibo.runbox.com) (91.220.196.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 10 Jan 2014 21:20:46 +0000 Received: from [10.9.9.206] (helo=mailfront02.runbox.com) by bars.runbox.com with esmtp (Exim 4.71) (envelope-from ) id 1W1jVR-0006Q8-VO; Fri, 10 Jan 2014 22:20:42 +0100 Received: from 70-36-239-203.dsl.dynamic.sonic.net ([70.36.239.203] helo=localhost.localdomain) by mailfront02.runbox.com with esmtpsa (uid:757155 ) (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) id 1W1jVD-00030N-PX; Fri, 10 Jan 2014 22:20:28 +0100 Message-ID: <52D06419.4080302@bothner.com> Date: Fri, 10 Jan 2014 21:20:00 -0000 From: Per Bothner User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Jamison Hope , "kawa@sourceware.org list" Subject: Re: Support Iterable in for-each References: <52D048D4.2080803@bothner.com> <596354A4-C4B3-40B6-BCED-2FCF1CB1B9C5@theptrgroup.com> In-Reply-To: <596354A4-C4B3-40B6-BCED-2FCF1CB1B9C5@theptrgroup.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-q1/txt/msg00006.txt.bz2 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. -- --Per Bothner per@bothner.com http://per.bothner.com/