Skip to content

Commit

Permalink
Fix copy-on-write in TimetableSnapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
vpaturet committed Jul 1, 2024
1 parent 15cf5f8 commit 940a45e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main/java/org/opentripplanner/model/TimetableSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,23 @@ public boolean revertTripToScheduledTripPattern(FeedScopedId tripId, LocalDate s
}

if (tripTimesToRemove != null) {
for (Timetable sortedTimetable : sortedTimetables) {
boolean isDirty = sortedTimetable.getTripTimes().remove(tripTimesToRemove);
for (Timetable originalTimetable : sortedTimetables) {
boolean isDirty = originalTimetable.getTripTimes().contains(tripTimesToRemove);
if (isDirty) {
dirtyTimetables.add(sortedTimetable);
Timetable updatedTimetable;
if (dirtyTimetables.contains(originalTimetable)) {
// the timetable has already been copied-on-write in this snapshot
// no need to copy it again
updatedTimetable = originalTimetable;
} else {
// create a copy of this timetable and swap the copy and the original
updatedTimetable = new Timetable(originalTimetable, serviceDate);
sortedTimetables.remove(originalTimetable);
sortedTimetables.add(updatedTimetable);
dirtyTimetables.add(updatedTimetable);
dirty = true;
}
updatedTimetable.getTripTimes().remove(tripTimesToRemove);
}
}
}
Expand Down

0 comments on commit 940a45e

Please sign in to comment.