Skip to content

Don't use <Duration as Display>::display() in time passes #25419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/librustc/util/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,24 @@ pub fn time<T, U, F>(do_it: bool, what: &str, u: U, f: F) -> T where
r
});

let mut u = Some(u);
let mut rv = None;
let dur = {
let ref mut rvp = rv;

Duration::span(move || {
*rvp = Some(f(u.take().unwrap()))
*rvp = Some(f(u))
})
};
let rv = rv.unwrap();

println!("{}time: {} \t{}", repeat(" ").take(old).collect::<String>(),
dur, what);
// Hack up our own formatting for the duration to make it easier for scripts
// to parse (always use the same number of decimal places and the same unit).
const NANOS_PER_SEC: f64 = 1_000_000_000.0;
let secs = dur.secs() as f64;
let secs = secs + dur.extra_nanos() as f64 / NANOS_PER_SEC;
println!("{}time: {:.3} \t{}", repeat(" ").take(old).collect::<String>(),
secs, what);

DEPTH.with(|slot| slot.set(old));

rv
Expand Down