From 7133fb43b7138554d8485717e54ab8dce1d43cac Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Wed, 20 Jul 2011 22:09:17 +0000 Subject: [PATCH] =?UTF-8?q?MATH-623=20Slightly=20faster=20"add"=20method?= =?UTF-8?q?=20(due=20to=20Arne=20Pl=C3=B6se).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1148952 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/math/linear/ArrayRealVector.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java b/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java index 6bd719176..762371739 100644 --- a/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java +++ b/src/main/java/org/apache/commons/math/linear/ArrayRealVector.java @@ -304,12 +304,14 @@ public class ArrayRealVector extends AbstractRealVector implements Serializable /** {@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; } /**