From ab8c02fb115964f2be4048880ecba771a7137d50 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 16 Mar 2024 07:52:48 -0400 Subject: [PATCH] One less boolean operation per primitive append() --- .../commons/lang3/builder/EqualsBuilder.java | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java index ff5276b04..18fc56b76 100644 --- a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java @@ -438,10 +438,9 @@ public class EqualsBuilder implements Builder { * @return this */ public EqualsBuilder append(final byte lhs, final byte rhs) { - if (!isEquals) { - return this; + if (isEquals) { + isEquals = lhs == rhs; } - isEquals = lhs == rhs; return this; } @@ -484,10 +483,9 @@ public class EqualsBuilder implements Builder { * @return this */ public EqualsBuilder append(final char lhs, final char rhs) { - if (!isEquals) { - return this; + if (isEquals) { + isEquals = lhs == rhs; } - isEquals = lhs == rhs; return this; } @@ -536,10 +534,10 @@ public class EqualsBuilder implements Builder { * @return this */ public EqualsBuilder append(final double lhs, final double rhs) { - if (!isEquals) { - return this; + if (isEquals) { + return append(Double.doubleToLongBits(lhs), Double.doubleToLongBits(rhs)); } - return append(Double.doubleToLongBits(lhs), Double.doubleToLongBits(rhs)); + return this; } /** @@ -587,10 +585,10 @@ public class EqualsBuilder implements Builder { * @return this */ public EqualsBuilder append(final float lhs, final float rhs) { - if (!isEquals) { - return this; + if (isEquals) { + return append(Float.floatToIntBits(lhs), Float.floatToIntBits(rhs)); } - return append(Float.floatToIntBits(lhs), Float.floatToIntBits(rhs)); + return this; } /** @@ -632,10 +630,9 @@ public class EqualsBuilder implements Builder { * @return this */ public EqualsBuilder append(final int lhs, final int rhs) { - if (!isEquals) { - return this; + if (isEquals) { + isEquals = lhs == rhs; } - isEquals = lhs == rhs; return this; } @@ -680,10 +677,9 @@ public class EqualsBuilder implements Builder { * @return this */ public EqualsBuilder append(final long lhs, final long rhs) { - if (!isEquals) { - return this; + if (isEquals) { + isEquals = lhs == rhs; } - isEquals = lhs == rhs; return this; } @@ -796,10 +792,9 @@ public class EqualsBuilder implements Builder { * @return this */ public EqualsBuilder append(final short lhs, final short rhs) { - if (!isEquals) { - return this; + if (isEquals) { + isEquals = lhs == rhs; } - isEquals = lhs == rhs; return this; }