From c7c85ee39892df3ca007c6596c41654865be7e43 Mon Sep 17 00:00:00 2001 From: pascalschumacher Date: Tue, 30 Aug 2016 21:53:54 +0200 Subject: [PATCH] LANG-1262: CompareToBuilder.append(Object, Object, Comparator) method is too big to be inlined Extracted arrays processing into a separate method. --- src/changes/changes.xml | 1 + .../lang3/builder/CompareToBuilder.java | 53 ++++++++++--------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c038ad8b5..8e7dccb46 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -46,6 +46,7 @@ The type attribute can be add,update,fix,remove. + CompareToBuilder.append(Object, Object, Comparator) method is too big to be inlined Remove unnecessary synchronization from registry lookup in EqualsBuilder and HashCodeBuilder Extend RandomStringUtils with methods that generate strings between a min and max length Handle "void" in ClassUtils.getClass() diff --git a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java index 56d2fcd91..e79a1c915 100644 --- a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java @@ -418,30 +418,8 @@ public CompareToBuilder append(final Object lhs, final Object rhs, final Compara return this; } if (lhs.getClass().isArray()) { - // switch on type of array, to dispatch to the correct handler - // handles multi dimensional arrays - // throws a ClassCastException if rhs is not the correct array type - if (lhs instanceof long[]) { - append((long[]) lhs, (long[]) rhs); - } else if (lhs instanceof int[]) { - append((int[]) lhs, (int[]) rhs); - } else if (lhs instanceof short[]) { - append((short[]) lhs, (short[]) rhs); - } else if (lhs instanceof char[]) { - append((char[]) lhs, (char[]) rhs); - } else if (lhs instanceof byte[]) { - append((byte[]) lhs, (byte[]) rhs); - } else if (lhs instanceof double[]) { - append((double[]) lhs, (double[]) rhs); - } else if (lhs instanceof float[]) { - append((float[]) lhs, (float[]) rhs); - } else if (lhs instanceof boolean[]) { - append((boolean[]) lhs, (boolean[]) rhs); - } else { - // not an array of primitives - // throws a ClassCastException if rhs is not an array - append((Object[]) lhs, (Object[]) rhs, comparator); - } + // factor out array case in order to keep method small enough to be inlined + appendArray(lhs, rhs, comparator); } else { // the simple case, not an array, just test the element if (comparator == null) { @@ -457,6 +435,33 @@ public CompareToBuilder append(final Object lhs, final Object rhs, final Compara return this; } + private void appendArray(final Object lhs, final Object rhs, final Comparator comparator) { + // switch on type of array, to dispatch to the correct handler + // handles multi dimensional arrays + // throws a ClassCastException if rhs is not the correct array type + if (lhs instanceof long[]) { + append((long[]) lhs, (long[]) rhs); + } else if (lhs instanceof int[]) { + append((int[]) lhs, (int[]) rhs); + } else if (lhs instanceof short[]) { + append((short[]) lhs, (short[]) rhs); + } else if (lhs instanceof char[]) { + append((char[]) lhs, (char[]) rhs); + } else if (lhs instanceof byte[]) { + append((byte[]) lhs, (byte[]) rhs); + } else if (lhs instanceof double[]) { + append((double[]) lhs, (double[]) rhs); + } else if (lhs instanceof float[]) { + append((float[]) lhs, (float[]) rhs); + } else if (lhs instanceof boolean[]) { + append((boolean[]) lhs, (boolean[]) rhs); + } else { + // not an array of primitives + // throws a ClassCastException if rhs is not an array + append((Object[]) lhs, (Object[]) rhs, comparator); + } + } + //------------------------------------------------------------------------- /** * Appends to the builder the comparison of