commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1408805 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/ResizableDoubleArray.java
Date Tue, 13 Nov 2012 15:55:26 GMT
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.



Mime
View raw message