Skip to content

Commit 8496c8c

Browse files
committed
Reuse Integer.compareUnsigned(int, int)
1 parent efdc3bd commit 8496c8c

1 file changed

Lines changed: 2 additions & 19 deletions

File tree

src/main/java/org/apache/commons/codec/binary/BaseNCodec.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,6 @@ public String toString() {
190190
*/
191191
static final byte[] CHUNK_SEPARATOR = {'\r', '\n'};
192192

193-
/**
194-
* Compares two {@code int} values numerically treating the values
195-
* as unsigned. Taken from JDK 1.8.
196-
*
197-
* <p>TODO: Replace with JDK 1.8 Integer::compareUnsigned(int, int).</p>
198-
*
199-
* @param x the first {@code int} to compare
200-
* @param y the second {@code int} to compare
201-
* @return the value {@code 0} if {@code x == y}; a value less
202-
* than {@code 0} if {@code x < y} as unsigned values; and
203-
* a value greater than {@code 0} if {@code x > y} as
204-
* unsigned values
205-
*/
206-
private static int compareUnsigned(final int x, final int y) {
207-
return Integer.compare(x + Integer.MIN_VALUE, y + Integer.MIN_VALUE);
208-
}
209-
210193
/**
211194
* Create a positive capacity at least as large the minimum required capacity.
212195
* If the minimum capacity is negative then this throws an OutOfMemoryError as no array
@@ -273,10 +256,10 @@ private static byte[] resizeBuffer(final Context context, final int minCapacity)
273256
// Overflow-conscious code treats the min and new capacity as unsigned.
274257
final int oldCapacity = context.buffer.length;
275258
int newCapacity = oldCapacity * DEFAULT_BUFFER_RESIZE_FACTOR;
276-
if (compareUnsigned(newCapacity, minCapacity) < 0) {
259+
if (Integer.compareUnsigned(newCapacity, minCapacity) < 0) {
277260
newCapacity = minCapacity;
278261
}
279-
if (compareUnsigned(newCapacity, MAX_BUFFER_SIZE) > 0) {
262+
if (Integer.compareUnsigned(newCapacity, MAX_BUFFER_SIZE) > 0) {
280263
newCapacity = createPositiveCapacity(minCapacity);
281264
}
282265

0 commit comments

Comments
 (0)