speed up the trip table tab. on lakeslice at 8am, down from ~0.3s to
~0.005s in release mode
@@ -11,7 +11,7 @@ use ezgui::{
};
use geom::{Distance, Duration, Polygon, Pt2D, Time};
use sim::{TripEndpoint, TripID, TripMode};
-use std::collections::BTreeSet;
+use std::collections::{BTreeSet, HashMap};
const ROWS: usize = 10;
@@ -179,6 +179,19 @@ struct Entry {
}
fn make(ctx: &mut EventCtx, app: &App, opts: &Options) -> Composite {
+ // Only make one pass through prebaked data
+ let trip_times_before = if app.has_prebaked().is_some() {
+ let mut times = HashMap::new();
+ for (_, id, maybe_mode, dt) in &app.prebaked().finished_trips {
+ if maybe_mode.is_some() {
+ times.insert(*id, *dt);
+ }
+ }
+ Some(times)
+ } else {
+ None
+ };
+
// Gather raw data
let mut data = Vec::new();
let sim = &app.primary.sim;
@@ -193,7 +206,7 @@ fn make(ctx: &mut EventCtx, app: &App, opts: &Options) -> Composite {
aborted += 1;
continue;
};
- let (_, start, end, _) = sim.trip_info(*id);
+ let (departure, start, end, _) = sim.trip_info(*id);
if !opts.off_map_starts {
if let TripEndpoint::Border(_, _) = start {
continue;
@@ -206,10 +219,9 @@ fn make(ctx: &mut EventCtx, app: &App, opts: &Options) -> Composite {
}
let (_, waiting) = sim.finished_trip_time(*id).unwrap();
- let (departure, _, _, _) = sim.trip_info(*id);
- let duration_before = if app.has_prebaked().is_some() {
- if let Some(dt) = app.prebaked().finished_trip_time(*id) {
- dt
+ let duration_before = if let Some(ref times) = trip_times_before {
+ if let Some(dt) = times.get(id) {
+ *dt
} else {
// Aborted
aborted += 1;
