From dev-return-39593-apmail-harmony-dev-archive=harmony.apache.org@harmony.apache.org Thu Aug 05 09:26:30 2010 Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 64864 invoked from network); 5 Aug 2010 09:26:30 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 5 Aug 2010 09:26:30 -0000 Received: (qmail 6255 invoked by uid 500); 5 Aug 2010 09:26:30 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 5949 invoked by uid 500); 5 Aug 2010 09:26:26 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 5938 invoked by uid 99); 5 Aug 2010 09:26:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Aug 2010 09:26:25 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of oliver.deakin@googlemail.com designates 74.125.82.41 as permitted sender) Received: from [74.125.82.41] (HELO mail-ww0-f41.google.com) (74.125.82.41) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Aug 2010 09:26:18 +0000 Received: by wwa36 with SMTP id 36so587027wwa.0 for ; Thu, 05 Aug 2010 02:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=8t0wg/AUQnNbaukqStS5TkR9XcKe5l8fbxSgwJsJG/0=; b=M+4HSuFNx0lmYaxgbqwdUc/5aUCfAw35dw6/ZxSipcKQY6qA8RDO8rT0x19zLO9qBQ yLQoHEPpBqvz8uJWKFi3rq1AefzxEXbSw/yAMVtdVzC4oe5sQ5CBFX0IN31awBpCNysp KT9HYBgYn9Uo3/osVeV/i1s+Deh7ZVrH/0MBo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=fKcXpeEzfqdABRZA0fkw78kKC6/1EqHxgQOQVmzjcNhmn+eD+hDGQXT6EULRYhr+n0 JlGPS4NAOR+TVSJlf8qA70VMSXL6IHA1oaN9vip4NFcmmZOl9+9+vallezEXZAKbhoXM pLANVk/vmUvfaJ7aa4RieH1S+19BHGJTSKq7A= Received: by 10.216.48.146 with SMTP id v18mr8988467web.56.1281000357155; Thu, 05 Aug 2010 02:25:57 -0700 (PDT) Received: from [9.20.183.165] (gbibp9ph1--blueice4n1.emea.ibm.com [195.212.29.91]) by mx.google.com with ESMTPS id u11sm4908690weq.7.2010.08.05.02.25.55 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 05 Aug 2010 02:25:55 -0700 (PDT) Message-ID: <4C5A83A1.9000509@googlemail.com> Date: Thu, 05 Aug 2010 10:25:53 +0100 From: Oliver Deakin User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.7) Gecko/20100713 Thunderbird/3.1.1 MIME-Version: 1.0 To: dev@harmony.apache.org Subject: Re: svn commit: r982498 - /harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/util/ArrayList.java References: <20100805081850.CED0D23889D5@eris.apache.org> In-Reply-To: <20100805081850.CED0D23889D5@eris.apache.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 05/08/2010 09:18, hindessm@apache.org wrote: > Author: hindessm > Date: Thu Aug 5 08:18:50 2010 > New Revision: 982498 > > URL: http://svn.apache.org/viewvc?rev=982498&view=rev > Log: > Refactor so we track firstIndex and size rather than firstIndex and lastIndex. > I also changed ensureCapacity to calculate "minimumCapacity - array.length" > once rather than three times. > Still need to simplify the serialization code. > > Modified: > harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/util/ArrayList.java > > Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/util/ArrayList.java > URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/util/ArrayList.java?rev=982498&r1=982497&r2=982498&view=diff > ============================================================================== > --- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/util/ArrayList.java (original) > +++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/util/ArrayList.java Thu Aug 5 08:18:50 2010 > > public void ensureCapacity(int minimumCapacity) { > - if (array.length< minimumCapacity) { > + int required = minimumCapacity - array.length; > + if (required> 0) { > // REVIEW: Why do we check the firstIndex first? Growing > // the end makes more sense > if (firstIndex> 0) { > - growAtFront(minimumCapacity - array.length); > + growAtFront(required); > } else { > - growAtEnd(minimumCapacity - array.length); > + growAtEnd(required); > } > } > } This change to ensureCapacity() actually modifies its behaviour and looks to fix a bug in the process (perhaps accidentally?). Originally, if minimumCapacity was equal to array.length, we would enter the if block and call growAtFront()/growAtEnd() with required==0 resulting in a completely needless array copy and fill. With this change the check has been reversed but has omitted the case where required == 0, so we no longer do the unnecessary work. Looks like a good bug fix to me! Regards, Oliver