diff --git a/abstutil/src/io.rs b/abstutil/src/io.rs index 5cdcd4e7f6..7dc628a399 100644 --- a/abstutil/src/io.rs +++ b/abstutil/src/io.rs @@ -41,18 +41,18 @@ pub fn maybe_read_json(path: String, timer: &mut Timer) -> panic!("read_json needs {} to end with .json or .geojson", path); } - timer.start(&format!("parse {}", path)); + timer.start(format!("parse {}", path)); // TODO timer.read_file isn't working here. And we need to call stop() if there's no file. match File::open(&path) { Ok(mut file) => { let mut contents = String::new(); file.read_to_string(&mut contents)?; let obj: T = serde_json::from_str(&contents)?; - timer.stop(&format!("parse {}", path)); + timer.stop(format!("parse {}", path)); Ok(obj) } Err(e) => { - timer.stop(&format!("parse {}", path)); + timer.stop(format!("parse {}", path)); Err(e) } } @@ -182,7 +182,7 @@ pub fn list_all_objects(dir: String) -> Vec { // Load all serialized things from a directory, return sorted by name, with file extension removed. // Detects JSON or binary. pub fn load_all_objects(dir: String) -> Vec<(String, T)> { - let mut timer = Timer::new(&format!("load_all_objects from {}", dir)); + let mut timer = Timer::new(format!("load_all_objects from {}", dir)); let mut tree: BTreeMap = BTreeMap::new(); match std::fs::read_dir(&dir) { Ok(iter) => { diff --git a/abstutil/src/time.rs b/abstutil/src/time.rs index 86dc9bd55a..88d4ed5731 100644 --- a/abstutil/src/time.rs +++ b/abstutil/src/time.rs @@ -19,9 +19,9 @@ struct Progress { } impl Progress { - fn new(label: &str, total_items: usize) -> Progress { + fn new(label: String, total_items: usize) -> Progress { Progress { - label: label.to_string(), + label, processed_items: 0, total_items, started_at: Instant::now(), @@ -120,11 +120,12 @@ struct TimerSpan { } impl<'a> Timer<'a> { - pub fn new(name: &str) -> Timer<'a> { + pub fn new>(raw_name: S) -> Timer<'a> { + let name = raw_name.into(); let mut t = Timer { results: Vec::new(), stack: Vec::new(), - outermost_name: name.to_string(), + outermost_name: name.clone(), notes: Vec::new(), warnings: Vec::new(), sink: None, @@ -175,24 +176,26 @@ impl<'a> Timer<'a> { // Used to end the scope of a timer early. pub fn done(self) {} - pub fn start(&mut self, name: &str) { + pub fn start>(&mut self, raw_name: S) { if self.outermost_name == "throwaway" { return; } + let name = raw_name.into(); self.println(format!("{}...", name)); self.stack.push(StackEntry::TimerSpan(TimerSpan { - name: name.to_string(), + name, started_at: Instant::now(), nested_results: Vec::new(), nested_time: 0.0, })); } - pub fn stop(&mut self, name: &str) { + pub fn stop>(&mut self, raw_name: S) { if self.outermost_name == "throwaway" { return; } + let name = raw_name.into(); let span = match self.stack.pop().unwrap() { StackEntry::TimerSpan(s) => s, @@ -246,13 +249,14 @@ impl<'a> Timer<'a> { self.println(line); } - pub fn start_iter(&mut self, name: &str, total_items: usize) { + pub fn start_iter>(&mut self, raw_name: S, total_items: usize) { if self.outermost_name == "throwaway" { return; } if total_items == 0 { return; } + let name = raw_name.into(); if let Some(StackEntry::Progress(p)) = self.stack.last() { panic!( "Can't start_iter({}) while Progress({}) is top of the stack", diff --git a/convert_osm/src/main.rs b/convert_osm/src/main.rs index fcc5851675..9251db8137 100644 --- a/convert_osm/src/main.rs +++ b/convert_osm/src/main.rs @@ -15,7 +15,7 @@ fn main() { }; args.done(); - let mut timer = abstutil::Timer::new(&format!("generate {}", flags.output)); + let mut timer = abstutil::Timer::new(format!("generate {}", flags.output)); let map = convert(&flags, &mut timer); timer.start("saving map"); abstutil::write_binary(flags.output, &map); diff --git a/ezgui/src/event_ctx.rs b/ezgui/src/event_ctx.rs index 9af1215cad..9282384791 100644 --- a/ezgui/src/event_ctx.rs +++ b/ezgui/src/event_ctx.rs @@ -21,20 +21,21 @@ pub struct EventCtx<'a> { } impl<'a> EventCtx<'a> { - pub fn loading_screen O>( + pub fn loading_screen, F: FnOnce(&mut EventCtx, &mut Timer) -> O>( &mut self, - timer_name: &str, + raw_timer_name: S, f: F, ) -> O { + let timer_name = raw_timer_name.into(); let mut timer = Timer::new_with_sink( - timer_name, + &timer_name, Box::new(LoadingScreen::new( self.prerender, self.program, self.assets, self.canvas.window_width, self.canvas.window_height, - timer_name.to_string(), + timer_name.clone(), )), ); f(self, &mut timer) diff --git a/game/src/abtest/setup.rs b/game/src/abtest/setup.rs index bb92148739..94661085d4 100644 --- a/game/src/abtest/setup.rs +++ b/game/src/abtest/setup.rs @@ -118,7 +118,7 @@ fn make_load_savestate(ab_test: ABTest) -> Box { fn launch_test(test: &ABTest, ui: &mut UI, ctx: &mut EventCtx) -> ABTestMode { let secondary = ctx.loading_screen( - &format!("Launching A/B test {}", test.test_name), + format!("Launching A/B test {}", test.test_name), |ctx, mut timer| { let scenario: Scenario = abstutil::read_binary( abstutil::path_scenario(&test.map_name, &test.scenario_name), @@ -213,7 +213,7 @@ fn launch_test(test: &ABTest, ui: &mut UI, ctx: &mut EventCtx) -> ABTestMode { fn launch_savestate(test: &ABTest, ss_path: String, ui: &mut UI, ctx: &mut EventCtx) -> ABTestMode { ctx.loading_screen( - &format!("Launch A/B test from savestate {}", ss_path), + format!("Launch A/B test from savestate {}", ss_path), |ctx, mut timer| { let ss: ABTestSavestate = abstutil::read_binary(ss_path, &mut timer); diff --git a/game/src/challenges.rs b/game/src/challenges.rs index 439eb667d8..724cc4ab7d 100644 --- a/game/src/challenges.rs +++ b/game/src/challenges.rs @@ -267,11 +267,11 @@ pub fn prebake() { } } for (map_path, list) in per_map { - timer.start(&format!("prebake for {}", map_path)); + timer.start(format!("prebake for {}", map_path)); let map = map_model::Map::new(map_path.clone(), false, &mut timer); for challenge in list { - timer.start(&format!("prebake for {}", challenge.title)); + timer.start(format!("prebake for {}", challenge.title)); if let Some(scenario) = challenge.gameplay.scenario(&map, None, &mut timer) { let mut sim = Sim::new(&map, SimOptions::new("prebaked"), &mut timer); // Bit of an abuse of this, but just need to fix the rng seed. @@ -284,9 +284,9 @@ pub fn prebake() { sim.get_analytics(), ); } - timer.stop(&format!("prebake for {}", challenge.title)); + timer.stop(format!("prebake for {}", challenge.title)); } - timer.stop(&format!("prebake for {}", map_path)); + timer.stop(format!("prebake for {}", map_path)); } } diff --git a/game/src/debug/color_picker.rs b/game/src/debug/color_picker.rs index 68d1672b42..e2fd517693 100644 --- a/game/src/debug/color_picker.rs +++ b/game/src/debug/color_picker.rs @@ -23,7 +23,7 @@ fn pick_color(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option TrafficSignalEditor { ui.primary.current_selection = None; let menu = ModalMenu::new( - &format!("Traffic Signal Editor for {}", id), + format!("Traffic Signal Editor for {}", id), vec![ (hotkey(Key::UpArrow), "select previous phase"), (hotkey(Key::DownArrow), "select next phase"), diff --git a/game/src/mission/neighborhood.rs b/game/src/mission/neighborhood.rs index 4bccec60a6..5a7a5d230b 100644 --- a/game/src/mission/neighborhood.rs +++ b/game/src/mission/neighborhood.rs @@ -27,7 +27,7 @@ impl State for NeighborhoodPicker { self.wizard = Wizard::new(); return Transition::Push(Box::new(NeighborhoodEditor { menu: ModalMenu::new( - &format!("Neighborhood Editor for {}", n.name), + format!("Neighborhood Editor for {}", n.name), vec![ (hotkey(Key::Escape), "quit"), (hotkey(Key::S), "save"), diff --git a/game/src/sandbox/gameplay/faster_trips.rs b/game/src/sandbox/gameplay/faster_trips.rs index 27800cc77b..e46977cd80 100644 --- a/game/src/sandbox/gameplay/faster_trips.rs +++ b/game/src/sandbox/gameplay/faster_trips.rs @@ -16,7 +16,7 @@ impl FasterTrips { pub fn new(trip_mode: TripMode, ctx: &EventCtx) -> (ModalMenu, Box) { ( ModalMenu::new( - &format!("Speed up {} trips", trip_mode), + format!("Speed up {} trips", trip_mode), vec![(hotkey(Key::H), "help")], ctx, ), diff --git a/game/src/sandbox/gameplay/optimize_bus.rs b/game/src/sandbox/gameplay/optimize_bus.rs index 29fa9d1565..d76b6eca65 100644 --- a/game/src/sandbox/gameplay/optimize_bus.rs +++ b/game/src/sandbox/gameplay/optimize_bus.rs @@ -21,7 +21,7 @@ impl OptimizeBus { let route = ui.primary.map.get_bus_route(&route_name).unwrap(); ( ModalMenu::new( - &format!("Optimize {}", route_name), + format!("Optimize {}", route_name), vec![ (hotkey(Key::E), "show bus route"), (hotkey(Key::T), "show delays over time"), diff --git a/game/src/sandbox/gameplay/play_scenario.rs b/game/src/sandbox/gameplay/play_scenario.rs index ecd0ec8402..4982a6e065 100644 --- a/game/src/sandbox/gameplay/play_scenario.rs +++ b/game/src/sandbox/gameplay/play_scenario.rs @@ -11,7 +11,7 @@ impl PlayScenario { pub fn new(name: &String, ctx: &EventCtx) -> (ModalMenu, Box) { ( ModalMenu::new( - &format!("Playing {}", name), + format!("Playing {}", name), vec![ (hotkey(Key::S), "start another scenario"), (lctrl(Key::L), "load another map"), diff --git a/popdat/src/psrc.rs b/popdat/src/psrc.rs index cae6e1f10e..5b39fc79e2 100644 --- a/popdat/src/psrc.rs +++ b/popdat/src/psrc.rs @@ -158,7 +158,7 @@ fn import_parcels( // TODO Ideally we could just do the conversion directly without any dependencies, but the // formats are documented quite confusingly. Couldn't get the Rust crate for proj or GDAL // bindings to build. So just do this hack. - timer.start(&format!( + timer.start(format!( "run cs2cs on {} points", prettyprint_usize(parcel_metadata.len()) )); @@ -176,7 +176,7 @@ fn import_parcels( ]) .output()?; assert!(output.status.success()); - timer.stop(&format!( + timer.stop(format!( "run cs2cs on {} points", prettyprint_usize(parcel_metadata.len()) )); diff --git a/precompute/src/main.rs b/precompute/src/main.rs index f46ac8b811..1214e6b723 100644 --- a/precompute/src/main.rs +++ b/precompute/src/main.rs @@ -9,7 +9,7 @@ fn main() { let use_fixes = !args.enabled("--nofixes"); args.done(); - let mut timer = Timer::new(&format!("precompute {}", load)); + let mut timer = Timer::new(format!("precompute {}", load)); let map = Map::new(load, use_fixes, &mut timer); timer.start("save map"); diff --git a/sim/src/make/scenario.rs b/sim/src/make/scenario.rs index 4885b632e0..af378d66af 100644 --- a/sim/src/make/scenario.rs +++ b/sim/src/make/scenario.rs @@ -88,7 +88,7 @@ impl Scenario { pub fn instantiate(&self, sim: &mut Sim, map: &Map, rng: &mut XorShiftRng, timer: &mut Timer) { sim.set_name(self.scenario_name.clone()); - timer.start(&format!("Instantiating {}", self.scenario_name)); + timer.start(format!("Instantiating {}", self.scenario_name)); if self.seed_buses { for route in map.get_all_bus_routes() { @@ -156,7 +156,7 @@ impl Scenario { } sim.spawn_all_trips(map, timer, true); - timer.stop(&format!("Instantiating {}", self.scenario_name)); + timer.stop(format!("Instantiating {}", self.scenario_name)); } pub fn save(&self) { diff --git a/sim/src/sim.rs b/sim/src/sim.rs index 9f6c7c2d1f..5d7c43a846 100644 --- a/sim/src/sim.rs +++ b/sim/src/sim.rs @@ -583,7 +583,7 @@ impl Sim { // TODO Ideally print every second or so let orig_time = self.time; let chunks = (dt / Duration::seconds(10.0)).ceil() as usize; - timer.start_iter(&format!("advance simulation by {}", dt), chunks); + timer.start_iter(format!("advance simulation by {}", dt), chunks); for i in 0..chunks { timer.next(); self.step(