changeset 380:5f55047a17e8

Moved expensive allocation of result arrays out of km loop. flys-artifacts/trunk@1795 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 02 May 2011 16:28:57 +0000
parents c21fb8de54f8
children 52b6de9d0ab4
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java
diffstat 4 files changed, 27 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon May 02 15:17:04 2011 +0000
+++ b/flys-artifacts/ChangeLog	Mon May 02 16:28:57 2011 +0000
@@ -1,3 +1,17 @@
+2011-05-02	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java:
+	  Added interpolateW method to take reference to result ws array
+	  as an argument to avoid expensive array allocations in km iterating
+	  loops.
+
+	* src/main/java/de/intevation/flys/artifacts/model/WQKms.java:
+	  Added a constructor to create backing trove datastructure
+	  with the right capacity.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Move allocation of result ws out of km loop.
+
 2011-05-02  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/conf/artifacts/winfo.xml: Added two further data items in the WQ
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Mon May 02 15:17:04 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Mon May 02 16:28:57 2011 +0000
@@ -284,11 +284,13 @@
 
         WQKms[] wqkms = new WQKms[qs.length];
         for (int i = 0; i < wqkms.length; i++) {
-            wqkms[i] = new WQKms();
+            wqkms[i] = new WQKms(kms.length);
         }
 
+        double [] interpolatedW = new double[qs.length];
+
         for (double km: kms) {
-            double[] interpolatedW = wst.interpolateW(km, qs);
+            wst.interpolateW(km, qs, interpolatedW);
 
             // TODO Modify the interpolation to return a better formed data
             // structure.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java	Mon May 02 15:17:04 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java	Mon May 02 16:28:57 2011 +0000
@@ -29,6 +29,12 @@
         this.kms = new TDoubleArrayList();
     }
 
+    public WQKms(int capacity) {
+        this.w   = new TDoubleArrayList(capacity);
+        this.q   = new TDoubleArrayList(capacity);
+        this.kms = new TDoubleArrayList(capacity);
+    }
+
 
     /**
      * Adds a new row to this data pool.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Mon May 02 15:17:04 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Mon May 02 16:28:57 2011 +0000
@@ -349,10 +349,11 @@
         this.columns = columns;
     }
 
-
     public double [] interpolateW(double km, double [] qs) {
+        return interpolateW(km, qs, new double[qs.length]);
+    }
 
-        double [] ws = new double[qs.length];
+    public double [] interpolateW(double km, double [] qs, double [] ws) {
 
         int rowIndex = Collections.binarySearch(rows, new Row(km));
 

http://dive4elements.wald.intevation.org