You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Jörg Schaible <jo...@gmx.de> on 2010/01/09 15:39:48 UTC
Fwd: svn commit: r897419 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
Well, if you know that it is an array, you might check the compount type to be
a primitive and in case it is, you might use == for the primitive types.
--------------- Weitergeleitete Nachricht (Anfang)
Betreff: svn commit: r897419 -
/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
Absender: bayard-1oDqGaOF3Lkdnm+yROfE0A@public.gmane.org
Datum: Sat, 09 Jan 2010 11:20:49 +0000
Newsgruppe: gmane.comp.jakarta.commons.scm
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;
}
--------------- Weitergeleitete Nachricht (Ende)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org