[GitHub] [commons-compress] garydgregory commented on a change in pull request #247: Use Math.min and Math.max calculations.

2022-02-18 Thread GitBox


garydgregory commented on a change in pull request #247:
URL: https://github.com/apache/commons-compress/pull/247#discussion_r810065740



##
File path: 
src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
##
@@ -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));

Review comment:
   Parens around the call to max are not needed. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [commons-compress] garydgregory commented on a change in pull request #247: Use Math.min and Math.max calculations.

2022-02-17 Thread GitBox


garydgregory commented on a change in pull request #247:
URL: https://github.com/apache/commons-compress/pull/247#discussion_r809425316



##
File path: 
src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java
##
@@ -877,11 +876,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));

Review comment:
   No need for extra parens to wrap arguments to the min call.

##
File path: 
src/main/java/org/apache/commons/compress/harmony/pack200/BHSDCodec.java
##
@@ -308,11 +308,8 @@ public boolean encodes(final long value) {
 }
 } 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).
-}
+// this value is equal to (1 << 32).

Review comment:
   So... now what?

##
File path: 
src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java
##
@@ -877,11 +876,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));

Review comment:
   No need for extra parens to wrap arguments to the min call.

##
File path: 
src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
##
@@ -244,10 +244,7 @@ private static void hbMakeCodeLengths(final byte[] len, 
final int[] freq,
 final int weight_n2 = weight[n2];
 weight[nNodes] = ((weight_n1 & 0xff00)
   + (weight_n2 & 0xff00))
-| (1 + (((weight_n1 & 0x00ff)
- > (weight_n2 & 0x00ff))
-? (weight_n1 & 0x00ff)
-: (weight_n2 & 0x00ff)));
+| (1 + (Math.max((weight_n1 & 0x00ff), (weight_n2 & 
0x00ff;

Review comment:
   No need for extra parens to wrap arguments to the min call.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [commons-compress] garydgregory commented on a change in pull request #247: Use Math.min and Math.max calculations.

2022-02-15 Thread GitBox


garydgregory commented on a change in pull request #247:
URL: https://github.com/apache/commons-compress/pull/247#discussion_r806121231



##
File path: 
src/main/java/org/apache/commons/compress/harmony/pack200/BHSDCodec.java
##
@@ -308,11 +308,8 @@ public boolean encodes(final long value) {
 }
 } 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).
-}
+// this value is equal to (1 << 32).

Review comment:
   I think you'd want to use jshell here, not python...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [commons-compress] garydgregory commented on a change in pull request #247: Use Math.min and Math.max calculations.

2022-02-14 Thread GitBox


garydgregory commented on a change in pull request #247:
URL: https://github.com/apache/commons-compress/pull/247#discussion_r806121231



##
File path: 
src/main/java/org/apache/commons/compress/harmony/pack200/BHSDCodec.java
##
@@ -308,11 +308,8 @@ public boolean encodes(final long value) {
 }
 } 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).
-}
+// this value is equal to (1 << 32).

Review comment:
   I think you'd want to use jshell here, not python...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org