carterkozak commented on a change in pull request #326:
URL: 
https://github.com/apache/httpcomponents-client/pull/326#discussion_r750325863



##########
File path: 
httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpByteArrayCacheEntrySerializerTestUtils.java
##########
@@ -320,9 +321,7 @@ private static int readFully(final InputStream src, final 
byte[] dest) throws IO
      *                     number of bytes have been read
      */
     static byte[] readFullyStrict(final InputStream src, final long length) 
throws IOException {
-        if (length > Integer.MAX_VALUE) {
-            throw new IllegalArgumentException(String.format("Length %d is too 
large to fit in an array", length));
-        }
+        Args.check(length <= Integer.MAX_VALUE, String.format("Length %d is 
too large to fit in an array", length));

Review comment:
       This `String.format` is very expensive, and now it's executed in both 
the valid path and invalid path, where previously the work was avoided unless 
it was necessary. I think this should probably be reverted.
   
   Also note that refactoring into the following will yield more efficient code 
(but to be clear, it doesn't really matter much if it's not executed in most 
cases):
   ```java
   "Length " + length + " is too large to fit in an array"
   ```
   
   on java 8 this produces:
   ```java
   new StringBuilder().append("Length ").append(length).append(" is too large 
to fit in an array").build()
   ```
   
   and once we target java 11 bytecode will take advantage of 
[jep-280](https://openjdk.java.net/jeps/280) `StringConcatFactory.makeConcat`.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to