From 878ae8eb3c3b93fe0cb8b25daeb0ceb16da37801 Mon Sep 17 00:00:00 2001 From: Koen De Groote Date: Fri, 12 May 2017 16:36:13 +0200 Subject: [PATCH] Size lists in advance when known When constructing an array list, if we know the size of the list in advance (because we are adding objects to it derived from another list), we should size the array list to the appropriate capacity in advance (to avoid resizing allocations). This commit does this in various places. Relates #24439 --- .../cluster/repositories/get/GetRepositoriesResponse.java | 2 +- .../admin/cluster/snapshots/get/GetSnapshotsResponse.java | 2 +- .../action/admin/cluster/stats/ClusterStatsNodes.java | 4 ++-- .../action/admin/indices/get/GetIndexResponse.java | 2 +- .../action/support/tasks/BaseTasksResponse.java | 4 ++-- .../org/elasticsearch/cluster/block/ClusterBlock.java | 2 +- .../common/inject/assistedinject/AssistedConstructor.java | 2 +- .../index/analysis/CustomAnalyzerProvider.java | 4 ++-- .../index/analysis/CustomNormalizerProvider.java | 4 ++-- .../org/elasticsearch/index/mapper/DynamicTemplate.java | 2 +- .../elasticsearch/index/query/AbstractQueryBuilder.java | 2 +- .../elasticsearch/index/query/GeoPolygonQueryBuilder.java | 2 +- .../snapshots/blobstore/BlobStoreIndexShardSnapshots.java | 2 +- .../indices/breaker/HierarchyCircuitBreakerService.java | 2 +- .../search/aggregations/AggregatorFactories.java | 2 +- .../search/aggregations/BucketCollector.java | 2 +- .../adjacency/AdjacencyMatrixAggregationBuilder.java | 2 +- .../bucket/filters/FiltersAggregationBuilder.java | 2 +- .../search/aggregations/bucket/terms/DoubleTerms.java | 2 +- .../cumulativesum/CumulativeSumPipelineAggregator.java | 2 +- .../org/elasticsearch/ingest/common/ConvertProcessor.java | 2 +- .../org/elasticsearch/ingest/common/DateProcessor.java | 2 +- .../src/main/java/org/elasticsearch/painless/Def.java | 2 +- .../java/org/elasticsearch/painless/node/ELambda.java | 8 ++++---- .../discovery/ec2/AwsEc2UnicastHostsProvider.java | 4 ++-- .../repositories/gcs/GoogleCloudStorageBlobStore.java | 2 +- .../org/elasticsearch/bootstrap/BootstrapForTesting.java | 2 +- .../test/rest/yaml/ClientYamlTestExecutionContext.java | 2 +- 28 files changed, 36 insertions(+), 36 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesResponse.java index c933156fcb0..6d4cb839345 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/get/GetRepositoriesResponse.java @@ -60,7 +60,7 @@ public class GetRepositoriesResponse extends ActionResponse implements Iterable< public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); - List repositoryListBuilder = new ArrayList<>(); + List repositoryListBuilder = new ArrayList<>(size); for (int j = 0; j < size; j++) { repositoryListBuilder.add(new RepositoryMetaData( in.readString(), diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java index 308a846c905..0d1e5eda7f2 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java @@ -59,7 +59,7 @@ public class GetSnapshotsResponse extends ActionResponse implements ToXContentOb public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); - List builder = new ArrayList<>(); + List builder = new ArrayList<>(size); for (int i = 0; i < size; i++) { builder.add(new SnapshotInfo(in)); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java index 27276b27dd9..41cacf2a851 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java @@ -65,8 +65,8 @@ public class ClusterStatsNodes implements ToXContent { this.plugins = new HashSet<>(); Set seenAddresses = new HashSet<>(nodeResponses.size()); - List nodeInfos = new ArrayList<>(); - List nodeStats = new ArrayList<>(); + List nodeInfos = new ArrayList<>(nodeResponses.size()); + List nodeStats = new ArrayList<>(nodeResponses.size()); for (ClusterStatsNodeResponse nodeResponse : nodeResponses) { nodeInfos.add(nodeResponse.nodeInfo()); nodeStats.add(nodeResponse.nodeStats()); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java index 6c2e4627523..36bfa81a334 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java @@ -114,7 +114,7 @@ public class GetIndexResponse extends ActionResponse { for (int i = 0; i < aliasesSize; i++) { String key = in.readString(); int valueSize = in.readVInt(); - List aliasEntryBuilder = new ArrayList<>(); + List aliasEntryBuilder = new ArrayList<>(valueSize); for (int j = 0; j < valueSize; j++) { aliasEntryBuilder.add(new AliasMetaData(in)); } diff --git a/core/src/main/java/org/elasticsearch/action/support/tasks/BaseTasksResponse.java b/core/src/main/java/org/elasticsearch/action/support/tasks/BaseTasksResponse.java index b62cfd714bb..4ddbe541993 100644 --- a/core/src/main/java/org/elasticsearch/action/support/tasks/BaseTasksResponse.java +++ b/core/src/main/java/org/elasticsearch/action/support/tasks/BaseTasksResponse.java @@ -81,13 +81,13 @@ public class BaseTasksResponse extends ActionResponse { public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); - List taskFailures = new ArrayList<>(); + List taskFailures = new ArrayList<>(size); for (int i = 0; i < size; i++) { taskFailures.add(new TaskOperationFailure(in)); } size = in.readVInt(); this.taskFailures = Collections.unmodifiableList(taskFailures); - List nodeFailures = new ArrayList<>(); + List nodeFailures = new ArrayList<>(size); for (int i = 0; i < size; i++) { nodeFailures.add(new FailedNodeException(in)); } diff --git a/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java b/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java index 253206222b4..f09e1dd9cda 100644 --- a/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java +++ b/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java @@ -125,7 +125,7 @@ public class ClusterBlock implements Streamable, ToXContent { id = in.readVInt(); description = in.readString(); final int len = in.readVInt(); - ArrayList levels = new ArrayList<>(); + ArrayList levels = new ArrayList<>(len); for (int i = 0; i < len; i++) { levels.add(ClusterBlockLevel.fromId(in.readVInt())); } diff --git a/core/src/main/java/org/elasticsearch/common/inject/assistedinject/AssistedConstructor.java b/core/src/main/java/org/elasticsearch/common/inject/assistedinject/AssistedConstructor.java index edd45c290a5..cb434a90369 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/assistedinject/AssistedConstructor.java +++ b/core/src/main/java/org/elasticsearch/common/inject/assistedinject/AssistedConstructor.java @@ -49,7 +49,7 @@ class AssistedConstructor { Annotation[][] annotations = constructor.getParameterAnnotations(); List typeList = new ArrayList<>(); - allParameters = new ArrayList<>(); + allParameters = new ArrayList<>(parameterTypes.size()); // categorize params as @Assisted or @Injected for (int i = 0; i < parameterTypes.size(); i++) { diff --git a/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java index 282edaeaf73..f1123045622 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/CustomAnalyzerProvider.java @@ -55,8 +55,8 @@ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider charFiltersList = new ArrayList<>(); String[] charFilterNames = analyzerSettings.getAsArray("char_filter"); + List charFiltersList = new ArrayList<>(charFilterNames.length); for (String charFilterName : charFilterNames) { CharFilterFactory charFilter = charFilters.get(charFilterName); if (charFilter == null) { @@ -65,8 +65,8 @@ public class CustomAnalyzerProvider extends AbstractIndexAnalyzerProvider tokenFilterList = new ArrayList<>(); String[] tokenFilterNames = analyzerSettings.getAsArray("filter"); + List tokenFilterList = new ArrayList<>(tokenFilterNames.length); for (String tokenFilterName : tokenFilterNames) { TokenFilterFactory tokenFilter = tokenFilters.get(tokenFilterName); if (tokenFilter == null) { diff --git a/core/src/main/java/org/elasticsearch/index/analysis/CustomNormalizerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/CustomNormalizerProvider.java index 4f50a34dd9e..2fcc987df6a 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/CustomNormalizerProvider.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/CustomNormalizerProvider.java @@ -50,8 +50,8 @@ public final class CustomNormalizerProvider extends AbstractIndexAnalyzerProvide throw new IllegalArgumentException("Custom normalizer [" + name() + "] cannot configure a tokenizer"); } - List charFiltersList = new ArrayList<>(); String[] charFilterNames = analyzerSettings.getAsArray("char_filter"); + List charFiltersList = new ArrayList<>(charFilterNames.length); for (String charFilterName : charFilterNames) { CharFilterFactory charFilter = charFilters.get(charFilterName); if (charFilter == null) { @@ -66,8 +66,8 @@ public final class CustomNormalizerProvider extends AbstractIndexAnalyzerProvide charFiltersList.add(charFilter); } - List tokenFilterList = new ArrayList<>(); String[] tokenFilterNames = analyzerSettings.getAsArray("filter"); + List tokenFilterList = new ArrayList<>(tokenFilterNames.length); for (String tokenFilterName : tokenFilterNames) { TokenFilterFactory tokenFilter = tokenFilters.get(tokenFilterName); if (tokenFilter == null) { diff --git a/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java b/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java index b07492740ae..ca8fcd1ffd8 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/DynamicTemplate.java @@ -318,7 +318,7 @@ public class DynamicTemplate implements ToXContent { } private List processList(List list, String name, String dynamicType) { - List processedList = new ArrayList(); + List processedList = new ArrayList(list.size()); for (Object value : list) { if (value instanceof Map) { value = processMap((Map) value, name, dynamicType); diff --git a/core/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java index 6a3cd2f1ed5..9d18e42138d 100644 --- a/core/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java @@ -250,8 +250,8 @@ public abstract class AbstractQueryBuilder> } protected static final List readQueries(StreamInput in) throws IOException { - List queries = new ArrayList<>(); int size = in.readVInt(); + List queries = new ArrayList<>(size); for (int i = 0; i < size; i++) { queries.add(in.readNamedWriteable(QueryBuilder.class)); } diff --git a/core/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryBuilder.java index cc25ac4772a..1f9e81cecc1 100644 --- a/core/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/GeoPolygonQueryBuilder.java @@ -163,7 +163,7 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder shell = new ArrayList(); + List shell = new ArrayList<>(this.shell.size()); for (GeoPoint geoPoint : this.shell) { shell.add(new GeoPoint(geoPoint)); } diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java index 359c3165f53..56c343a5ae9 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java @@ -284,7 +284,7 @@ public class BlobStoreIndexShardSnapshots implements Iterable, To } } - List snapshots = new ArrayList<>(); + List snapshots = new ArrayList<>(snapshotsMap.size()); for (Map.Entry> entry : snapshotsMap.entrySet()) { List fileInfosBuilder = new ArrayList<>(); for (String file : entry.getValue()) { diff --git a/core/src/main/java/org/elasticsearch/indices/breaker/HierarchyCircuitBreakerService.java b/core/src/main/java/org/elasticsearch/indices/breaker/HierarchyCircuitBreakerService.java index 88cff7f559a..b8ec92ba153 100644 --- a/core/src/main/java/org/elasticsearch/indices/breaker/HierarchyCircuitBreakerService.java +++ b/core/src/main/java/org/elasticsearch/indices/breaker/HierarchyCircuitBreakerService.java @@ -177,7 +177,7 @@ public class HierarchyCircuitBreakerService extends CircuitBreakerService { @Override public AllCircuitBreakerStats stats() { long parentEstimated = 0; - List allStats = new ArrayList<>(); + List allStats = new ArrayList<>(this.breakers.size()); // Gather the "estimated" count for the parent breaker by adding the // estimations for each individual breaker for (CircuitBreaker breaker : this.breakers.values()) { diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java b/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java index 106335380cc..d635952ec15 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java @@ -183,7 +183,7 @@ public class AggregatorFactories { } public List createPipelineAggregators() throws IOException { - List pipelineAggregators = new ArrayList<>(); + List pipelineAggregators = new ArrayList<>(this.pipelineAggregatorFactories.size()); for (PipelineAggregationBuilder factory : this.pipelineAggregatorFactories) { pipelineAggregators.add(factory.create()); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/BucketCollector.java b/core/src/main/java/org/elasticsearch/search/aggregations/BucketCollector.java index 2de6ae0cf93..40e66bd9645 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/BucketCollector.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/BucketCollector.java @@ -70,7 +70,7 @@ public abstract class BucketCollector implements Collector { @Override public LeafBucketCollector getLeafCollector(LeafReaderContext ctx) throws IOException { - List leafCollectors = new ArrayList<>(); + List leafCollectors = new ArrayList<>(collectors.length); for (BucketCollector c : collectors) { leafCollectors.add(c.getLeafCollector(ctx)); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/adjacency/AdjacencyMatrixAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/adjacency/AdjacencyMatrixAggregationBuilder.java index 526db6a79b7..eeb60d393e5 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/adjacency/AdjacencyMatrixAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/adjacency/AdjacencyMatrixAggregationBuilder.java @@ -197,7 +197,7 @@ public class AdjacencyMatrixAggregationBuilder extends AbstractAggregationBuilde + "] index level setting."); } - List rewrittenFilters = new ArrayList<>(); + List rewrittenFilters = new ArrayList<>(filters.size()); for (KeyedFilter kf : filters) { rewrittenFilters.add(new KeyedFilter(kf.key(), QueryBuilder.rewriteQuery(kf.filter(), context.getQueryShardContext()))); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregationBuilder.java index f34df7368ac..b80ce74c3da 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregationBuilder.java @@ -169,7 +169,7 @@ public class FiltersAggregationBuilder extends AbstractAggregationBuilder doBuild(SearchContext context, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { - List rewrittenFilters = new ArrayList<>(); + List rewrittenFilters = new ArrayList<>(filters.size()); for(KeyedFilter kf : filters) { rewrittenFilters.add(new KeyedFilter(kf.key(), QueryBuilder.rewriteQuery(kf.filter(), context.getQueryShardContext()))); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTerms.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTerms.java index e4885bc0539..b87ce51c4bd 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTerms.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTerms.java @@ -164,7 +164,7 @@ public class DoubleTerms extends InternalMappedTerms newAggs = new ArrayList<>(); + List newAggs = new ArrayList<>(aggregations.size()); for (InternalAggregation agg : aggregations) { if (agg instanceof LongTerms) { DoubleTerms dTerms = LongTerms.convertLongTermsToDouble((LongTerms) agg, format); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregator.java index e79ba1047e2..8a1b70fdd14 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregator.java @@ -75,7 +75,7 @@ public class CumulativeSumPipelineAggregator extends PipelineAggregator { InternalMultiBucketAggregation.InternalBucket>) aggregation; List buckets = histo.getBuckets(); HistogramFactory factory = (HistogramFactory) histo; - List newBuckets = new ArrayList<>(); + List newBuckets = new ArrayList<>(buckets.size()); double sum = 0; for (InternalMultiBucketAggregation.InternalBucket bucket : buckets) { Double thisBucketValue = resolveBucketValue(histo, bucket, bucketsPaths()[0], GapPolicy.INSERT_ZEROS); diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java index 3cf35c76117..8ecd4d99eb2 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java @@ -153,7 +153,7 @@ public final class ConvertProcessor extends AbstractProcessor { if (oldValue instanceof List) { List list = (List) oldValue; - List newList = new ArrayList<>(); + List newList = new ArrayList<>(list.size()); for (Object value : list) { newList.add(convertType.convert(value)); } diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateProcessor.java index 676cf2e7419..e6034138873 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateProcessor.java @@ -54,7 +54,7 @@ public final class DateProcessor extends AbstractProcessor { this.field = field; this.targetField = targetField; this.formats = formats; - this.dateParsers = new ArrayList<>(); + this.dateParsers = new ArrayList<>(this.formats.size()); for (String format : formats) { DateFormat dateFormat = DateFormat.fromString(format); dateParsers.add(dateFormat.getFunction(format, timezone, locale)); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java index dd1b51a5151..ebd25032220 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java @@ -240,7 +240,7 @@ public final class Def { } // convert recipe string to a bitset for convenience (the code below should be refactored...) - BitSet lambdaArgs = new BitSet(); + BitSet lambdaArgs = new BitSet(recipeString.length()); for (int i = 0; i < recipeString.length(); i++) { lambdaArgs.set(recipeString.charAt(i)); } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java index ad843f86af2..748ff67ddd4 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java @@ -113,7 +113,7 @@ public final class ELambda extends AExpression implements ILambda { // we don't know anything: treat as def returnType = Definition.DEF_TYPE; // don't infer any types, replace any null types with def - actualParamTypeStrs = new ArrayList<>(); + actualParamTypeStrs = new ArrayList<>(paramTypeStrs.size()); for (String type : paramTypeStrs) { if (type == null) { actualParamTypeStrs.add("def"); @@ -139,7 +139,7 @@ public final class ELambda extends AExpression implements ILambda { returnType = interfaceMethod.rtn; } // replace any null types with the actual type - actualParamTypeStrs = new ArrayList<>(); + actualParamTypeStrs = new ArrayList<>(paramTypeStrs.size()); for (int i = 0; i < paramTypeStrs.size(); i++) { String paramType = paramTypeStrs.get(i); if (paramType == null) { @@ -162,8 +162,8 @@ public final class ELambda extends AExpression implements ILambda { } } // prepend capture list to lambda's arguments - List paramTypes = new ArrayList<>(); - List paramNames = new ArrayList<>(); + List paramTypes = new ArrayList<>(captures.size() + actualParamTypeStrs.size()); + List paramNames = new ArrayList<>(captures.size() + paramNameStrs.size()); for (Variable var : captures) { paramTypes.add(var.type.name); paramNames.add(var.name); diff --git a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java index d428b953af1..91713ce2177 100644 --- a/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java +++ b/plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java @@ -125,8 +125,8 @@ class AwsEc2UnicastHostsProvider extends AbstractComponent implements UnicastHos // lets see if we can filter based on groups if (!groups.isEmpty()) { List instanceSecurityGroups = instance.getSecurityGroups(); - ArrayList securityGroupNames = new ArrayList(); - ArrayList securityGroupIds = new ArrayList(); + List securityGroupNames = new ArrayList<>(instanceSecurityGroups.size()); + List securityGroupIds = new ArrayList<>(instanceSecurityGroups.size()); for (GroupIdentifier sg : instanceSecurityGroups) { securityGroupNames.add(sg.getGroupName()); securityGroupIds.add(sg.getGroupId()); diff --git a/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStore.java b/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStore.java index 3c50c3a2a2d..225411f86dc 100644 --- a/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStore.java +++ b/plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStore.java @@ -249,7 +249,7 @@ class GoogleCloudStorageBlobStore extends AbstractComponent implements BlobStore deleteBlob(blobNames.iterator().next()); return; } - final List deletions = new ArrayList<>(); + final List deletions = new ArrayList<>(Math.min(MAX_BATCHING_REQUESTS, blobNames.size())); final Iterator blobs = blobNames.iterator(); SocketAccess.doPrivilegedVoidIOException(() -> { diff --git a/test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java b/test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java index c88b56abdd0..fbdab0b126b 100644 --- a/test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java +++ b/test/framework/src/main/java/org/elasticsearch/bootstrap/BootstrapForTesting.java @@ -201,7 +201,7 @@ public class BootstrapForTesting { codebases.removeAll(excluded); // parse each policy file, with codebase substitution from the classpath - final List policies = new ArrayList<>(); + final List policies = new ArrayList<>(pluginPolicies.size()); for (URL policyFile : pluginPolicies) { policies.add(Security.readPolicy(policyFile, codebases)); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java index c2c0f57c942..bea9aab3ff7 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java @@ -110,7 +110,7 @@ public class ClientYamlTestExecutionContext { ContentType.create(xContentType.mediaTypeWithoutParameters(), StandardCharsets.UTF_8)); } else { XContentType xContentType = getContentType(headers, STREAMING_CONTENT_TYPES); - List bytesRefList = new ArrayList<>(); + List bytesRefList = new ArrayList<>(bodies.size()); int totalBytesLength = 0; for (Map body : bodies) { BytesRef bytesRef = bodyAsBytesRef(body, xContentType);