Skip to content

Commit e9ebc2e

Browse files
committed
[self-profiler] Misc cleanups
1 parent 8170828 commit e9ebc2e

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/librustc/util/profiling.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,7 @@ impl CategoryResultData {
6969
}
7070

7171
fn total_time(&self) -> u64 {
72-
let mut total = 0;
73-
for (_, time) in &self.query_times {
74-
total += time;
75-
}
76-
77-
total
72+
self.query_times.iter().map(|(_, time)| time).sum()
7873
}
7974

8075
fn total_cache_data(&self) -> (u64, u64) {
@@ -133,13 +128,7 @@ impl CalculatedResults {
133128
}
134129

135130
fn total_time(&self) -> u64 {
136-
let mut total = 0;
137-
138-
for (_, data) in &self.categories {
139-
total += data.total_time();
140-
}
141-
142-
total
131+
self.categories.iter().map(|(_, data)| data.total_time()).sum()
143132
}
144133

145134
fn with_options(mut self, opts: &Options) -> CalculatedResults {
@@ -411,9 +400,9 @@ impl SelfProfiler {
411400
.unwrap();
412401

413402
let mut categories: Vec<_> = results.categories.iter().collect();
414-
categories.sort_by(|(_, data1), (_, data2)| data2.total_time().cmp(&data1.total_time()));
403+
categories.sort_by_cached_key(|(_, d)| d.total_time());
415404

416-
for (category, data) in categories {
405+
for (category, data) in categories.iter().rev() {
417406
let (category_hits, category_total) = data.total_cache_data();
418407
let category_hit_percent = calculate_percent(category_hits, category_total);
419408

0 commit comments

Comments
 (0)