Skip to content

Commit 746aa5d

Browse files
committed
NAVAND-1428: preallocate list size in PolylineUtils
1 parent 7879ee4 commit 746aa5d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

services-geojson/src/main/java/com/mapbox/geojson/utils/PolylineUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ public static List<Point> decode(@NonNull final String encodedPath, int precisio
4444

4545
// For speed we preallocate to an upper bound on the final length, then
4646
// truncate the array before returning.
47-
final List<Point> path = new ArrayList<>();
47+
final List<Point> path = new ArrayList<>((len + 1) / 2);
4848
int index = 0;
4949
int lat = 0;
5050
int lng = 0;
51+
int itemsCount = 0;
5152

5253
while (index < len) {
5354
int result = 1;
@@ -72,9 +73,10 @@ public static List<Point> decode(@NonNull final String encodedPath, int precisio
7273
lng += (result & 1) != 0 ? ~(result >> 1) : (result >> 1);
7374

7475
path.add(Point.fromLngLat(lng / factor, lat / factor));
76+
itemsCount++;
7577
}
7678

77-
return path;
79+
return path.subList(0, itemsCount);
7880
}
7981

8082
/**

0 commit comments

Comments
 (0)