Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/services/gtfs_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,10 @@ impl GTFSService {
.insert(stop.cluster.clone().unwrap(), cluster_stop_res);
}

stop_data.stops.insert(stop_code.to_string(), stop_res);
stop_data.stops.insert(stop_code.to_string(), stop_res.clone());
if stop.code != stop_code && !stop.code.is_empty() {
stop_data.stops.insert(stop.code.clone(), stop_res);
Comment on lines +792 to +794

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stop_res is cloned unconditionally to insert under stop_code, even when the alternate stop.code key is not inserted. This adds extra allocations per stop (potentially significant for large feeds). Consider inserting stop_res by move for the common case and only cloning when the alternate key is actually needed (e.g., branch on the condition and choose which insert gets the moved value).

Suggested change
stop_data.stops.insert(stop_code.to_string(), stop_res.clone());
if stop.code != stop_code && !stop.code.is_empty() {
stop_data.stops.insert(stop.code.clone(), stop_res);
if stop.code != stop_code && !stop.code.is_empty() {
stop_data
.stops
.insert(stop_code.to_string(), stop_res.clone());
stop_data.stops.insert(stop.code.clone(), stop_res);
} else {
stop_data.stops.insert(stop_code.to_string(), stop_res);

Copilot uses AI. Check for mistakes.

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new stop.code alias insertion uses HashMap::insert, which will silently overwrite an existing stop if another record already used the same stop.code key. Since GTFS stop_code is not guaranteed unique, this can lead to incorrect stop lookups depending on input ordering. Consider guarding against collisions (e.g., only insert if the key is vacant, or detect differing ids and log/skip/fail).

Suggested change
stop_data.stops.insert(stop.code.clone(), stop_res);
match stop_data.stops.entry(stop.code.clone()) {
std::collections::hash_map::Entry::Vacant(entry) => {
entry.insert(stop_res);
}
std::collections::hash_map::Entry::Occupied(entry) => {
if entry.get().id != stop_res.id {
// Preserve the first alias mapping and skip conflicting stop.code collisions.
}
}
}

Copilot uses AI. Check for mistakes.
}
}

stops_by_gtfs
Expand Down
Loading