commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1148952 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java
Date Wed, 20 Jul 2011 22:09:18 GMT
Author: erans
Date: Wed Jul 20 22:09:17 2011
New Revision: 1148952

URL: http://svn.apache.org/viewvc?rev=1148952&view=rev
Log:
MATH-623
Slightly faster "add" method (due to Arne Plöse).

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java?rev=1148952&r1=1148951&r2=1148952&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java
Wed Jul 20 22:09:17 2011
@@ -304,12 +304,14 @@ public class ArrayRealVector extends Abs
     /** {@inheritDoc} */
     @Override
     public RealVector add(double[] v) {
-        checkVectorDimensions(v.length);
-        double[] out = data.clone();
-        for (int i = 0; i < data.length; i++) {
-            out[i] += v[i];
+        final int dim = v.length;
+        checkVectorDimensions(dim);
+        ArrayRealVector result = new ArrayRealVector(dim);
+        double[] resultData = result.data;
+        for (int i = 0; i < dim; i++) {
+            resultData[i] = data[i] + v[i];
         }
-        return new ArrayRealVector(out, false);
+        return result;
     }
 
     /**



Mime
View raw message