Skip to content

Commit bd5038a

Browse files
committed
refactor(timings): fold the sections vec for readability
1 parent 6cd5ec3 commit bd5038a

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

src/cargo/core/compiler/timings/report.rs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::time::Instant;
88
use itertools::Itertools as _;
99

1010
use crate::CargoResult;
11-
use crate::core::compiler::CompilationSection;
1211
use crate::core::compiler::Unit;
1312

1413
use super::Concurrency;
@@ -436,38 +435,27 @@ fn aggregate_sections(unit_time: &UnitTime) -> AggregatedSections {
436435
// section, we need to iterate them and if an end is missing, we assign the end of
437436
// the section to the start of the following section.
438437

439-
let mut sections = vec![];
440-
441-
// The frontend section is currently implicit in rustc, it is assumed to start at
442-
// compilation start and end when codegen starts. So we hard-code it here.
443-
let mut previous_section = (
444-
SectionName::Frontend,
445-
CompilationSection {
446-
start: 0.0,
447-
end: None,
438+
let sections = unit_time.sections.clone().into_iter().fold(
439+
// The frontend section is currently implicit in rustc.
440+
// It is assumed to start at compilation start and end when codegen starts,
441+
// So we hard-code it here.
442+
vec![(SectionName::Frontend, SectionData { start: 0.0, end })],
443+
|mut sections, (name, section)| {
444+
let previous = sections.last_mut().unwrap();
445+
// Setting the end of previous to the start of the current.
446+
previous.1.end = section.start;
447+
448+
sections.push((
449+
SectionName::Named(name),
450+
SectionData {
451+
start: section.start,
452+
end: section.end.unwrap_or(end),
453+
},
454+
));
455+
456+
sections
448457
},
449458
);
450-
for (name, section) in unit_time.sections.clone() {
451-
// Store the previous section, potentially setting its end to the start of the
452-
// current section.
453-
sections.push((
454-
previous_section.0,
455-
SectionData {
456-
start: previous_section.1.start,
457-
end: previous_section.1.end.unwrap_or(section.start),
458-
},
459-
));
460-
previous_section = (SectionName::Named(name), section);
461-
}
462-
// Store the last section, potentially setting its end to the end of the whole
463-
// compilation.
464-
sections.push((
465-
previous_section.0,
466-
SectionData {
467-
start: previous_section.1.start,
468-
end: previous_section.1.end.unwrap_or(end),
469-
},
470-
));
471459

472460
AggregatedSections::Sections(sections)
473461
} else if let Some(rmeta) = unit_time.rmeta_time {

0 commit comments

Comments
 (0)