You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/03/16 13:46:47 UTC

[commons-codec] branch master updated: Reuse Integer.compareUnsigned(int, int)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git


The following commit(s) were added to refs/heads/master by this push:
     new 8496c8c8 Reuse Integer.compareUnsigned(int, int)
8496c8c8 is described below

commit 8496c8c8f2f9027d4ba12ce1e5f7a79b52fd29e9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Mar 16 09:46:42 2023 -0400

    Reuse Integer.compareUnsigned(int, int)
---
 .../org/apache/commons/codec/binary/BaseNCodec.java | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java b/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java
index 996024e1..50aa44fb 100644
--- a/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java
+++ b/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java
@@ -190,23 +190,6 @@ public abstract class BaseNCodec implements BinaryEncoder, BinaryDecoder {
      */
     static final byte[] CHUNK_SEPARATOR = {'\r', '\n'};
 
-    /**
-     * Compares two {@code int} values numerically treating the values
-     * as unsigned. Taken from JDK 1.8.
-     *
-     * <p>TODO: Replace with JDK 1.8 Integer::compareUnsigned(int, int).</p>
-     *
-     * @param  x the first {@code int} to compare
-     * @param  y the second {@code int} to compare
-     * @return the value {@code 0} if {@code x == y}; a value less
-     *         than {@code 0} if {@code x < y} as unsigned values; and
-     *         a value greater than {@code 0} if {@code x > y} as
-     *         unsigned values
-     */
-    private static int compareUnsigned(final int x, final int y) {
-        return Integer.compare(x + Integer.MIN_VALUE, y + Integer.MIN_VALUE);
-    }
-
     /**
      * Create a positive capacity at least as large the minimum required capacity.
      * If the minimum capacity is negative then this throws an OutOfMemoryError as no array
@@ -273,10 +256,10 @@ public abstract class BaseNCodec implements BinaryEncoder, BinaryDecoder {
         // Overflow-conscious code treats the min and new capacity as unsigned.
         final int oldCapacity = context.buffer.length;
         int newCapacity = oldCapacity * DEFAULT_BUFFER_RESIZE_FACTOR;
-        if (compareUnsigned(newCapacity, minCapacity) < 0) {
+        if (Integer.compareUnsigned(newCapacity, minCapacity) < 0) {
             newCapacity = minCapacity;
         }
-        if (compareUnsigned(newCapacity, MAX_BUFFER_SIZE) > 0) {
+        if (Integer.compareUnsigned(newCapacity, MAX_BUFFER_SIZE) > 0) {
             newCapacity = createPositiveCapacity(minCapacity);
         }