Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 94381 invoked from network); 29 Dec 2009 06:44:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Dec 2009 06:44:00 -0000 Received: (qmail 81277 invoked by uid 500); 29 Dec 2009 06:44:00 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 80766 invoked by uid 500); 29 Dec 2009 06:43:57 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 80748 invoked by uid 99); 29 Dec 2009 06:43:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Dec 2009 06:43:56 +0000 X-ASF-Spam-Status: No, hits=-10.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Dec 2009 06:43:50 +0000 Received: from brutus.apache.org (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id E7E9B234C1EF for ; Mon, 28 Dec 2009 22:43:29 -0800 (PST) Message-ID: <7828342.1262069009948.JavaMail.jira@brutus.apache.org> Date: Tue, 29 Dec 2009 06:43:29 +0000 (UTC) From: "Henri Yandell (JIRA)" To: issues@commons.apache.org Subject: [jira] Updated: (LANG-574) HashCodeBuilder append(Object) could be more efficient In-Reply-To: <1689896918.1261471589485.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LANG-574?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Henri Yandell updated LANG-574: ------------------------------- Fix Version/s: 3.0 > HashCodeBuilder append(Object) could be more efficient > ------------------------------------------------------ > > Key: LANG-574 > URL: https://issues.apache.org/jira/browse/LANG-574 > Project: Commons Lang > Issue Type: Improvement > Components: lang.builder.* > Affects Versions: 2.4 > Environment: Sun JDK 1.6.0_17 > Reporter: Anthony Whitford > Priority: Minor > Fix For: 3.0 > > > See: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang3/builder/HashCodeBuilder.java?view=markup > If you use *reflectionHashCode*, you will eventually call *reflectionAppend(Object)* for every field (see lines 859 to 890). There is a long list of _instanceOf_ checks for the various types of arrays. My concern is that having an array field is relatively rare, yet the code does 9 if/else checks before computing the _hashCode_ for _one_ element. I am thinking that it would make a lot of sense to wrap those if/else checks for the various array types in an *isArray* check (see Class.isArray). > If you look at the JDK source code for *Arrays.deepToString*, you will see that it checks if the class is an array before checking the various types. Note that since it gets the Class, it doesn't need to execute _instanceOf_ which is likely more expensive... > I have not done profiling, but I would not be surprised if short circuiting these checks could improve performance by an order of magnitude. The assumption is that getting the Class of an Object and asking it if it is an array is cheaper than asking _instanceOf_ 9 times. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.