From 8d518b77862b11c5fe074540e86c6a835ba01be4 Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Sat, 9 Jan 2010 11:20:49 +0000 Subject: [PATCH] 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 --- .../apache/commons/lang3/builder/HashCodeBuilder.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java index 717caa49a..16e216dd6 100644 --- a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java @@ -861,6 +861,8 @@ public class HashCodeBuilder { 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 @@ public class HashCodeBuilder { 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; }