Skip to content

Commit

Permalink
Eliminated extra array copy
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Dec 26, 2019
1 parent 1ac4425 commit a5942cb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion MapboxCoreNavigation/RouteLeg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Turf

extension RouteLeg {
var shape: LineString {
return LineString((steps.first?.shape?.coordinates ?? []) + steps.dropFirst().flatMap { ($0.shape?.coordinates ?? []).dropFirst() })
return steps.dropFirst().reduce(into: steps.first?.shape ?? LineString([])) { (result, step) in
result.coordinates += (step.shape?.coordinates ?? []).dropFirst()
}
}
}

0 comments on commit a5942cb

Please sign in to comment.