Author: erans
Date: Thu Jul 21 23:17:52 2011
New Revision: 1149405

URL: http://svn.apache.org/viewvc?rev=1149405&view=rev
Log:
MATH-623
Slightly more efficient implementation of some methods (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=1149405&r1=1149404&r2=1149405&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
 Thu Jul 21 23:17:52 2011
@@ -346,12 +346,14 @@ public class ArrayRealVector extends Abs
     /** {@inheritDoc} */
     @Override
     public RealVector subtract(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;
     }
 
     /**
@@ -434,12 +436,14 @@ public class ArrayRealVector extends Abs
     /** {@inheritDoc} */
     @Override
     public RealVector ebeMultiply(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;
     }
 
     /**
@@ -470,12 +474,14 @@ public class ArrayRealVector extends Abs
     /** {@inheritDoc} */
     @Override
     public RealVector ebeDivide(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;
     }
 
     /**


Reply via email to