Author: erans Date: Tue Nov 13 15:55:26 2012 New Revision: 1408805 URL: http://svn.apache.org/viewvc?rev=1408805&view=rev Log: Avoid duplicate computation.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/ResizableDoubleArray.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/ResizableDoubleArray.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/ResizableDoubleArray.java?rev=1408805&r1=1408804&r2=1408805&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/ResizableDoubleArray.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/ResizableDoubleArray.java Tue Nov 13 15:55:26 2012 @@ -432,9 +432,10 @@ public class ResizableDoubleArray implem LocalizedFormats.CANNOT_SUBSTITUTE_ELEMENT_FROM_EMPTY_ARRAY); } - double discarded = internalArray[startIndex + (numElements - 1)]; + final int substIndex = startIndex + (numElements - 1); + final double discarded = internalArray[substIndex]; - internalArray[startIndex + (numElements - 1)] = value; + internalArray[substIndex] = value; return discarded; } @@ -879,8 +880,9 @@ public class ResizableDoubleArray implem // Test the new num elements, check to see if the array needs to be // expanded to accommodate this new number of elements. - if ((startIndex + i) > internalArray.length) { - expandTo(startIndex + i); + final int newSize = startIndex + i; + if (newSize > internalArray.length) { + expandTo(newSize); } // Set the new number of elements to new value.