[ 
https://issues.apache.org/jira/browse/MATH-1564?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17245967#comment-17245967
 ] 

Alex Herbert commented on MATH-1564:
------------------------------------

The code differences in the PR generally changes the pattern:
{code:java}
T[] array = ...;
for (int i = 0; i< array.length; i++) {
    // Do something
}
{code}
to:
{code:java}
T[] array = ...;
final int arrayLength = array.length;
for (int i = 0; i< arrayLength; i++) {
    // Do something
}
{code}
I do not see this as an improvement.

{{array.length}} is accessing a constant field of the named array. Storing this 
as a separate local variable is unlikely to make any runtime difference. Unless 
you are performing something extremely trivial inside the loop the time 
difference between accessing {{array.length}} and {{arrayLength}} will be 
insignificant compared to the time spent inside the loop. At least using 
{{array.length}} makes the code readable.

This type of loop is something that is likely to be optimised by the JIT 
compiler. Do you have a reason for the changes?

 

> Minor improvement
> -----------------
>
>                 Key: MATH-1564
>                 URL: https://issues.apache.org/jira/browse/MATH-1564
>             Project: Commons Math
>          Issue Type: Improvement
>            Reporter: Arturo Bernal
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Minor improvement
>  * extra computations by getting the string size only once



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to