Repository: commons-lang Updated Branches: refs/heads/master f30c4607a -> c7c85ee39
LANG-1262: CompareToBuilder.append(Object, Object, Comparator) method is too big to be inlined Extracted arrays processing into a separate method. Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/c7c85ee3 Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/c7c85ee3 Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/c7c85ee3 Branch: refs/heads/master Commit: c7c85ee39892df3ca007c6596c41654865be7e43 Parents: f30c460 Author: pascalschumacher <pascalschumac...@gmx.net> Authored: Tue Aug 30 21:53:54 2016 +0200 Committer: pascalschumacher <pascalschumac...@gmx.net> Committed: Tue Aug 30 21:53:54 2016 +0200 ---------------------------------------------------------------------- src/changes/changes.xml | 1 + .../commons/lang3/builder/CompareToBuilder.java | 53 +++++++++++--------- 2 files changed, 30 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c7c85ee3/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c038ad8..8e7dccb 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove. <body> <release version="3.5" date="tba" description="tba"> + <action issue="LANG-1262" type="update" dev="pschumacher" due-to="Ruslan Cheremin">CompareToBuilder.append(Object, Object, Comparator) method is too big to be inlined</action> <action issue="LANG-1230" type="fix" dev="pschumacher" due-to="Philippe Marschall">Remove unnecessary synchronization from registry lookup in EqualsBuilder and HashCodeBuilder</action> <action issue="LANG-1224" type="add" dev="pschumacher" due-to="Caleb Cushing">Extend RandomStringUtils with methods that generate strings between a min and max length</action> <action issue="LANG-1214" type="fix" dev="pschumacher" due-to="Henry Tung">Handle "void" in ClassUtils.getClass()</action> http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c7c85ee3/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java ---------------------------------------------------------------------- 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 56d2fcd..e79a1c9 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 class CompareToBuilder implements Builder<Integer> { 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 class CompareToBuilder implements Builder<Integer> { 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 <code>builder</code> the comparison of