rosti-il commented on issue #318: [MNG-6853] - Don't box primitives where it's 
not needed
URL: https://github.com/apache/maven/pull/318#issuecomment-577638662
 
 
   @olamy This can only improve the performance because the `Integer.valueOf()` 
calls to the `Integer.parseInt()` by itself. The `Integer.parseInt()` returns a 
primitive while the `Integer.valueOf()` returns an object. Even when 
`Integer.valueOf()` returns a cached object and doesn't create a new one it 
executes the cache range check. Just take a look at the code of 
`java.lang.Integer` in JDK8.
   
       public static Integer valueOf(String s) throws NumberFormatException {
           return Integer.valueOf(parseInt(s, 10));
       }
   
       public static Integer valueOf(int i) {
           if (i >= IntegerCache.low && i <= IntegerCache.high)
               return IntegerCache.cache[i + (-IntegerCache.low)];
           return new Integer(i);
       }
   
       public static int parseInt(String s) throws NumberFormatException {
           return parseInt(s,10);
       }
   
   `valueOf()` and `parseLong()` of Long and Boolean are implemented by the 
same way.
   
   Also the code I propose to change uses primitives, so this change prevents 
unnecessary unboxing, i.e. it can only improve the performance.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to