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

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@897419 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2010-01-09 11:20:49 +00:00
parent 72e4ab4b00
commit 8d518b7786

View File

@ -861,6 +861,8 @@ public HashCodeBuilder append(Object object) {
iTotal = iTotal * iConstant; iTotal = iTotal * iConstant;
} else { } else {
Class clss = object.getClass();
if(clss.isArray()) {
// 'Switch' on type of array, to dispatch to the correct handler // 'Switch' on type of array, to dispatch to the correct handler
// This handles multi dimensional arrays // This handles multi dimensional arrays
if (object instanceof long[]) { if (object instanceof long[]) {
@ -879,9 +881,10 @@ public HashCodeBuilder append(Object object) {
append((float[]) object); append((float[]) object);
} else if (object instanceof boolean[]) { } else if (object instanceof boolean[]) {
append((boolean[]) object); append((boolean[]) object);
} else if (object instanceof Object[]) { } else {
// Not an array of primitives // Not an array of primitives
append((Object[]) object); append((Object[]) object);
}
} else { } else {
iTotal = iTotal * iConstant + object.hashCode(); iTotal = iTotal * iConstant + object.hashCode();
} }