From 9c82c679f86771f543ef8a712cbdd414a2ce0c87 Mon Sep 17 00:00:00 2001 From: David Brosius Date: Mon, 26 Aug 2013 03:18:55 +0000 Subject: [PATCH] presize collections git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1517418 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/math3/analysis/differentiation/DSCompiler.java | 2 +- .../distribution/MixtureMultivariateNormalDistribution.java | 2 +- .../math3/distribution/MixtureMultivariateRealDistribution.java | 2 +- .../MultivariateNormalMixtureExpectationMaximization.java | 2 +- .../apache/commons/math3/geometry/euclidean/threed/SubLine.java | 2 +- .../commons/math3/geometry/euclidean/twod/PolygonsSet.java | 2 +- .../apache/commons/math3/geometry/euclidean/twod/SubLine.java | 2 +- .../java/org/apache/commons/math3/ode/AbstractIntegrator.java | 2 +- .../org/apache/commons/math3/optim/linear/SimplexTableau.java | 2 +- .../commons/math3/optimization/linear/SimplexTableau.java | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java b/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java index b63ce8284..eb6c7d087 100644 --- a/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java +++ b/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java @@ -361,7 +361,7 @@ public class DSCompiler { for (int i = 0; i < dSize; ++i) { final int[][] dRow = derivativeCompiler.multIndirection[i]; - List row = new ArrayList(); + List row = new ArrayList(dRow.length * 2); for (int j = 0; j < dRow.length; ++j) { row.add(new int[] { dRow[j][0], lowerIndirection[dRow[j][1]], vSize + dRow[j][2] }); row.add(new int[] { dRow[j][0], vSize + dRow[j][1], lowerIndirection[dRow[j][2]] }); diff --git a/src/main/java/org/apache/commons/math3/distribution/MixtureMultivariateNormalDistribution.java b/src/main/java/org/apache/commons/math3/distribution/MixtureMultivariateNormalDistribution.java index 218255ad9..dc590e86d 100644 --- a/src/main/java/org/apache/commons/math3/distribution/MixtureMultivariateNormalDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/MixtureMultivariateNormalDistribution.java @@ -83,7 +83,7 @@ public class MixtureMultivariateNormalDistribution double[][] means, double[][][] covariances) { final List> mvns - = new ArrayList>(); + = new ArrayList>(weights.length); for (int i = 0; i < weights.length; i++) { final MultivariateNormalDistribution dist diff --git a/src/main/java/org/apache/commons/math3/distribution/MixtureMultivariateRealDistribution.java b/src/main/java/org/apache/commons/math3/distribution/MixtureMultivariateRealDistribution.java index 912ab0938..f0750ed03 100644 --- a/src/main/java/org/apache/commons/math3/distribution/MixtureMultivariateRealDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/MixtureMultivariateRealDistribution.java @@ -153,7 +153,7 @@ public class MixtureMultivariateRealDistribution> getComponents() { - final List> list = new ArrayList>(); + final List> list = new ArrayList>(weight.length); for (int i = 0; i < weight.length; i++) { list.add(new Pair(weight[i], distribution.get(i))); diff --git a/src/main/java/org/apache/commons/math3/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java b/src/main/java/org/apache/commons/math3/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java index 2f63b63d3..cc7b318f9 100644 --- a/src/main/java/org/apache/commons/math3/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java +++ b/src/main/java/org/apache/commons/math3/distribution/fitting/MultivariateNormalMixtureExpectationMaximization.java @@ -327,7 +327,7 @@ public class MultivariateNormalMixtureExpectationMaximization { // components of mixture model to be created final List> components = - new ArrayList>(); + new ArrayList>(numComponents); // create a component based on data in each bin for (int binIndex = 0; binIndex < numComponents; binIndex++) { diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java index aad7b65a5..62a91d1a2 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java @@ -81,7 +81,7 @@ public class SubLine { public List getSegments() { final List list = remainingRegion.asList(); - final List segments = new ArrayList(); + final List segments = new ArrayList(list.size()); for (final Interval interval : list) { final Vector3D start = line.toSpace(new Vector1D(interval.getInf())); diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java index 76ac1853c..5d8a992ce 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java @@ -186,7 +186,7 @@ public class PolygonsSet extends AbstractRegion { } // build the edges - List edges = new ArrayList(); + List edges = new ArrayList(n); for (int i = 0; i < n; ++i) { // get the endpoints of the edge diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java index ea9e96a49..b5d02a445 100644 --- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java +++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java @@ -81,7 +81,7 @@ public class SubLine extends AbstractSubHyperplane { final Line line = (Line) getHyperplane(); final List list = ((IntervalsSet) getRemainingRegion()).asList(); - final List segments = new ArrayList(); + final List segments = new ArrayList(list.size()); for (final Interval interval : list) { final Vector2D start = line.toSpace(new Vector1D(interval.getInf())); diff --git a/src/main/java/org/apache/commons/math3/ode/AbstractIntegrator.java b/src/main/java/org/apache/commons/math3/ode/AbstractIntegrator.java index 641812c51..38984355f 100644 --- a/src/main/java/org/apache/commons/math3/ode/AbstractIntegrator.java +++ b/src/main/java/org/apache/commons/math3/ode/AbstractIntegrator.java @@ -141,7 +141,7 @@ public abstract class AbstractIntegrator implements FirstOrderIntegrator { /** {@inheritDoc} */ public Collection getEventHandlers() { - final List list = new ArrayList(); + final List list = new ArrayList(eventsStates.size()); for (EventState state : eventsStates) { list.add(state.getEventHandler()); } diff --git a/src/main/java/org/apache/commons/math3/optim/linear/SimplexTableau.java b/src/main/java/org/apache/commons/math3/optim/linear/SimplexTableau.java index 1a696c03d..07f397b0e 100644 --- a/src/main/java/org/apache/commons/math3/optim/linear/SimplexTableau.java +++ b/src/main/java/org/apache/commons/math3/optim/linear/SimplexTableau.java @@ -269,7 +269,7 @@ class SimplexTableau implements Serializable { * @return new versions of the constraints */ public List normalizeConstraints(Collection originalConstraints) { - List normalized = new ArrayList(); + List normalized = new ArrayList(originalConstraints.size()); for (LinearConstraint constraint : originalConstraints) { normalized.add(normalize(constraint)); } diff --git a/src/main/java/org/apache/commons/math3/optimization/linear/SimplexTableau.java b/src/main/java/org/apache/commons/math3/optimization/linear/SimplexTableau.java index f5213c85a..e33e9a593 100644 --- a/src/main/java/org/apache/commons/math3/optimization/linear/SimplexTableau.java +++ b/src/main/java/org/apache/commons/math3/optimization/linear/SimplexTableau.java @@ -249,7 +249,7 @@ class SimplexTableau implements Serializable { * @return new versions of the constraints */ public List normalizeConstraints(Collection originalConstraints) { - List normalized = new ArrayList(); + List normalized = new ArrayList(originalConstraints.size()); for (LinearConstraint constraint : originalConstraints) { normalized.add(normalize(constraint)); }