# HG changeset patch # User Sascha L. Teichmann # Date 1304353737 0 # Node ID 5f55047a17e84bcbb221a1ed2568b91522a643c9 # Parent c21fb8de54f84699044ff9aaaf61baf037c7a4ab Moved expensive allocation of result arrays out of km loop. flys-artifacts/trunk@1795 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r c21fb8de54f8 -r 5f55047a17e8 flys-artifacts/ChangeLog --- 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 + + * 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 * doc/conf/artifacts/winfo.xml: Added two further data items in the WQ diff -r c21fb8de54f8 -r 5f55047a17e8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java --- 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. diff -r c21fb8de54f8 -r 5f55047a17e8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java --- 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. diff -r c21fb8de54f8 -r 5f55047a17e8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java --- 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));