commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r897419 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
Date Sat, 09 Jan 2010 11:20:49 GMT
Author: bayard
Date: Sat Jan  9 11:20:49 2010
New Revision: 897419

URL: http://svn.apache.org/viewvc?rev=897419&view=rev
Log:
Performance improvement per Anthony Whitford in LANG-574. Check for isArray to short-circuit
the 9 instanceof checks. Improves both non-arrays and Object[] in tests

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java?rev=897419&r1=897418&r2=897419&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
Sat Jan  9 11:20:49 2010
@@ -861,6 +861,8 @@
             iTotal = iTotal * iConstant;
 
         } else {
+            Class clss = object.getClass();
+            if(clss.isArray()) {
                 // 'Switch' on type of array, to dispatch to the correct handler
                 // This handles multi dimensional arrays
                 if (object instanceof long[]) {
@@ -879,12 +881,13 @@
                     append((float[]) object);
                 } else if (object instanceof boolean[]) {
                     append((boolean[]) object);
-                } else if (object instanceof Object[]) {
+                } else {
                     // Not an array of primitives
                     append((Object[]) object);
-                } else {
-                    iTotal = iTotal * iConstant + object.hashCode();
                 }
+            } else {
+                iTotal = iTotal * iConstant + object.hashCode();
+            }
         }
         return this;
     }



Mime
View raw message