Skip to content
Permalink
Browse files
Use Math.min and Math.max calculations. (#247)
  • Loading branch information
arturobernalg committed Feb 20, 2022
1 parent c3a8c55 commit 87fd7cbabeaebfcb02d87fb09e2c6a76c7aec010
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 22 deletions.
@@ -481,8 +481,7 @@ public int read(final byte[] buf, int off, int len) throws IOException {
}

while (len > 0) {
final int sz = len > readBuf.length - recordOffset
? readBuf.length - recordOffset : len;
final int sz = Math.min(len, readBuf.length - recordOffset);

// copy any data we have
if (recordOffset + sz <= readBuf.length) {
@@ -1361,7 +1361,7 @@ private void sanityCheckFilesInfo(final ByteBuffer header, final ArchiveStatisti
}
}
}
stats.numberOfEntriesWithStream = stats.numberOfEntries - (emptyStreams > 0 ? emptyStreams : 0);
stats.numberOfEntriesWithStream = stats.numberOfEntries - Math.max(emptyStreams, 0);
}

private void readFilesInfo(final ByteBuffer header, final Archive archive) throws IOException {
@@ -514,7 +514,7 @@ private void recvDecodingTables() throws IOException {
selectorMtf[i] = (byte) j;
}
}
final int nSelectors = selectors > MAX_SELECTORS ? MAX_SELECTORS : selectors;
final int nSelectors = Math.min(selectors, MAX_SELECTORS);

/* Undo the MTF values for the selectors. */
for (int v = nGroups; --v >= 0;) {
@@ -244,10 +244,7 @@ private static void hbMakeCodeLengths(final byte[] len, final int[] freq,
final int weight_n2 = weight[n2];
weight[nNodes] = ((weight_n1 & 0xffffff00)
+ (weight_n2 & 0xffffff00))
| (1 + (((weight_n1 & 0x000000ff)
> (weight_n2 & 0x000000ff))
? (weight_n1 & 0x000000ff)
: (weight_n2 & 0x000000ff)));
| (1 + Math.max(weight_n1 & 0x000000ff, weight_n2 & 0x000000ff));

parent[nNodes] = -1;
nHeap++;
@@ -118,8 +118,7 @@ class BlockSort {
private static final int FALLBACK_QSORT_STACK_SIZE = 100;

private static final int STACK_SIZE =
QSORT_STACK_SIZE < FALLBACK_QSORT_STACK_SIZE
? FALLBACK_QSORT_STACK_SIZE : QSORT_STACK_SIZE;
Math.max(QSORT_STACK_SIZE, FALLBACK_QSORT_STACK_SIZE);

/*
* Used when sorting. If too many long comparisons happen, we stop sorting,
@@ -317,7 +316,7 @@ private void fvswap(final int[] fmap, int yyp1, int yyp2, int yyn) {
}

private int fmin(final int a, final int b) {
return a < b ? a : b;
return Math.min(a, b);
}

private void fpush(final int sp, final int lz, final int hz) {
@@ -878,11 +877,9 @@ private void mainQSort3(final BZip2CompressorOutputStream.Data dataShadow,
stack_dd[sp] = d1;
sp++;
} else {
int n = ((ltLo - lo) < (unLo - ltLo)) ? (ltLo - lo)
: (unLo - ltLo);
int n = Math.min(ltLo - lo, unLo - ltLo);
vswap(fmap, lo, unLo - n, n);
int m = ((hi - gtHi) < (gtHi - unHi)) ? (hi - gtHi)
: (gtHi - unHi);
int m = Math.min(hi - gtHi, gtHi - unHi);
vswap(fmap, unLo, hi - m + 1, m);

n = lo + unLo - ltLo - 1;
@@ -469,7 +469,7 @@ private int literalLength() {
return length;
}
private static int lengths(final int litLength, final int brLength) {
final int l = litLength < 15 ? litLength : 15;
final int l = Math.min(litLength, 15);
final int br = brLength < 4 ? 0 : (brLength < 19 ? brLength - 4 : 15);
return (l << BlockLZ4CompressorInputStream.SIZE_BITS) | br;
}
@@ -310,11 +310,8 @@ public byte[] encode(final int value, final int last) throws Pack200Exception {
}
} else if (z < 0) {
// Need to use integer overflow here to represent negatives.
if (cardinality < 4294967296L) {
z += cardinality;
} else {
z += 4294967296L; // this value is equal to (1 << 32).
}
// 4294967296L is the 1 << 32.
z += Math.min(cardinality, 4294967296L);
}
if (z < 0) {
throw new Pack200Exception("unable to encode");
@@ -137,7 +137,7 @@ public static boolean isEqual(
final byte[] buffer1, final int offset1, final int length1,
final byte[] buffer2, final int offset2, final int length2,
final boolean ignoreTrailingNulls){
final int minLen=length1 < length2 ? length1 : length2;
final int minLen= Math.min(length1, length2);
for (int i=0; i < minLen; i++){
if (buffer1[offset1+i] != buffer2[offset2+i]){
return false;

0 comments on commit 87fd7cb

Please sign in to comment.