diff --git a/internal/restapi/stops_for_route_handler.go b/internal/restapi/stops_for_route_handler.go index 5581a1db..eb3148ca 100644 --- a/internal/restapi/stops_for_route_handler.go +++ b/internal/restapi/stops_for_route_handler.go @@ -388,7 +388,8 @@ func processTripGroups( func generatePolylines(shapes []gtfsdb.GetShapesGroupedByTripHeadSignRow) []models.Polyline { var polylines []models.Polyline - var coords [][]float64 + // This prevents repeated memory re-allocation during the loop. + coords := make([][]float64, 0, len(shapes)) for _, shape := range shapes { coords = append(coords, []float64{shape.Lat, shape.Lon}) }