Skip to content

Commit a271433

Browse files
committed
fix: improve ArrayList capacity allocation in GeoJson
1 parent 64f88ae commit a271433

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

Diff for: src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJson.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/**
2323
* Interface definition for structures defined in <a href="https://geojson.org">GeoJSON</a>
24-
* format. copied from Spring Data Mongodb
24+
* format. copied from Spring Data Mongodb
2525
*
2626
* @author Christoph Strobl
2727
* @since 1.7

Diff for: src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonLineString.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static GeoJsonLineString of(Point first, Point second, Point... others) {
6969
Assert.notNull(second, "Second point must not be null!");
7070
Assert.notNull(others, "Additional points must not be null!");
7171

72-
List<Point> points = new ArrayList<>();
72+
List<Point> points = new ArrayList<>(2 + others.length);
7373
points.add(first);
7474
points.add(second);
7575
points.addAll(Arrays.asList(others));
@@ -103,7 +103,7 @@ public static GeoJsonLineString of(GeoPoint first, GeoPoint second, GeoPoint...
103103
Assert.notNull(second, "Second point must not be null!");
104104
Assert.notNull(others, "Additional points must not be null!");
105105

106-
List<Point> points = new ArrayList<>();
106+
List<Point> points = new ArrayList<>(2 + others.length);
107107
points.add(GeoPoint.toPoint(first));
108108
points.add(GeoPoint.toPoint(second));
109109
points.addAll(Arrays.stream(others).map(GeoPoint::toPoint).collect(Collectors.toList()));

Diff for: src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonMultiPoint.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static GeoJsonMultiPoint of(Point first, Point second, Point... others) {
6969
Assert.notNull(second, "Second point must not be null!");
7070
Assert.notNull(others, "Additional points must not be null!");
7171

72-
List<Point> points = new ArrayList<>();
72+
List<Point> points = new ArrayList<>(2 + others.length);
7373
points.add(first);
7474
points.add(second);
7575
points.addAll(Arrays.asList(others));
@@ -103,7 +103,7 @@ public static GeoJsonMultiPoint of(GeoPoint first, GeoPoint second, GeoPoint...
103103
Assert.notNull(second, "Second point must not be null!");
104104
Assert.notNull(others, "Additional points must not be null!");
105105

106-
List<Point> points = new ArrayList<>();
106+
List<Point> points = new ArrayList<>(2 + others.length);
107107
points.add(GeoPoint.toPoint(first));
108108
points.add(GeoPoint.toPoint(second));
109109
points.addAll(Arrays.stream(others).map(GeoPoint::toPoint).collect(Collectors.toList()));

Diff for: src/main/java/org/springframework/data/elasticsearch/core/geo/GeoJsonPolygon.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public List<GeoJsonLineString> getCoordinates() {
189189
@SafeVarargs
190190
private static <T> List<T> asList(T first, T second, T third, T fourth, T... others) {
191191

192-
ArrayList<T> result = new ArrayList<>(3 + others.length);
192+
ArrayList<T> result = new ArrayList<>(4 + others.length);
193193

194194
result.add(first);
195195
result.add(second);

0 commit comments

Comments
 (0)