From e9ebc2e9561d285b0e9991943a834da18cb65c1f Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Sun, 10 Feb 2019 14:22:58 -0500 Subject: [PATCH] [self-profiler] Misc cleanups --- src/librustc/util/profiling.rs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/librustc/util/profiling.rs b/src/librustc/util/profiling.rs index a43b618ca90..c90bd12a310 100644 --- a/src/librustc/util/profiling.rs +++ b/src/librustc/util/profiling.rs @@ -69,12 +69,7 @@ fn new() -> CategoryResultData { } fn total_time(&self) -> u64 { - let mut total = 0; - for (_, time) in &self.query_times { - total += time; - } - - total + self.query_times.iter().map(|(_, time)| time).sum() } fn total_cache_data(&self) -> (u64, u64) { @@ -133,13 +128,7 @@ fn consolidate(mut cr1: CalculatedResults, cr2: CalculatedResults) -> Calculated } fn total_time(&self) -> u64 { - let mut total = 0; - - for (_, data) in &self.categories { - total += data.total_time(); - } - - total + self.categories.iter().map(|(_, data)| data.total_time()).sum() } fn with_options(mut self, opts: &Options) -> CalculatedResults { @@ -411,9 +400,9 @@ pub fn print_results(&mut self, opts: &Options) { .unwrap(); let mut categories: Vec<_> = results.categories.iter().collect(); - categories.sort_by(|(_, data1), (_, data2)| data2.total_time().cmp(&data1.total_time())); + categories.sort_by_cached_key(|(_, d)| d.total_time()); - for (category, data) in categories { + for (category, data) in categories.iter().rev() { let (category_hits, category_total) = data.total_cache_data(); let category_hit_percent = calculate_percent(category_hits, category_total);