Skip to content

Commit

Permalink
NAVAND-1428: preallocate list size in PolylineUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
dzinad committed Jul 31, 2023
1 parent 7879ee4 commit 746aa5d
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public static List<Point> decode(@NonNull final String encodedPath, int precisio

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

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

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

return path;
return path.subList(0, itemsCount);
}

/**
Expand Down

0 comments on commit 746aa5d

Please sign in to comment.