From 5a576e873e34eca47446850d41d5a33048a6ad21 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 29 Jun 2016 17:44:17 +0200 Subject: [PATCH] Move util::time::duration_from_seconds to profile::time --- components/profile/mem.rs | 2 +- components/profile/time.rs | 17 +++++++++++++++-- components/util/lib.rs | 1 - components/util/time.rs | 20 -------------------- 4 files changed, 16 insertions(+), 24 deletions(-) delete mode 100644 components/util/time.rs diff --git a/components/profile/mem.rs b/components/profile/mem.rs index 297584891c2..d1d2ca26b20 100644 --- a/components/profile/mem.rs +++ b/components/profile/mem.rs @@ -12,8 +12,8 @@ use std::borrow::ToOwned; use std::cmp::Ordering; use std::collections::HashMap; use std::thread; +use time::duration_from_seconds; use util::thread::spawn_named; -use util::time::duration_from_seconds; pub struct Profiler { /// The port through which messages are received. diff --git a/components/profile/time.rs b/components/profile/time.rs index 9c310fe9270..9c9debdb738 100644 --- a/components/profile/time.rs +++ b/components/profile/time.rs @@ -19,12 +19,11 @@ use std::io::{self, Write}; use std::path; use std::path::Path; use std::time::Duration; -use std::{thread, f64}; +use std::{f64, thread, u32, u64}; use std_time::precise_time_ns; use trace_dump::TraceDump; use util::opts::OutputOptions; use util::thread::spawn_named; -use util::time::duration_from_seconds; pub trait Formattable { fn format(&self, output: &Option) -> String; @@ -408,3 +407,17 @@ fn enforce_range(min: T, max: T, value: T) -> T where T: Ord { }, } } + +pub fn duration_from_seconds(secs: f64) -> Duration { + pub const NANOS_PER_SEC: u32 = 1_000_000_000; + + // Get number of seconds and check that it fits in a u64. + let whole_secs = secs.trunc(); + assert!(whole_secs >= 0.0 && whole_secs <= u64::MAX as f64); + + // Get number of nanoseconds. This should always fit in a u32, but check anyway. + let nanos = (secs.fract() * (NANOS_PER_SEC as f64)).trunc(); + assert!(nanos >= 0.0 && nanos <= u32::MAX as f64); + + Duration::new(whole_secs as u64, nanos as u32) +} diff --git a/components/util/lib.rs b/components/util/lib.rs index eed9c3e2a98..eb71fdf41f1 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -48,7 +48,6 @@ pub mod str; pub mod thread; pub mod thread_state; pub mod tid; -#[cfg(feature = "servo")] pub mod time; pub mod vec; #[allow(unsafe_code)] pub mod workqueue; diff --git a/components/util/time.rs b/components/util/time.rs deleted file mode 100644 index dab092b8850..00000000000 --- a/components/util/time.rs +++ /dev/null @@ -1,20 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use std::time::Duration; -use std::{u32, u64}; - -pub const NANOS_PER_SEC: u32 = 1_000_000_000; - -pub fn duration_from_seconds(secs: f64) -> Duration { - // Get number of seconds and check that it fits in a u64. - let whole_secs = secs.trunc(); - assert!(whole_secs >= 0.0 && whole_secs <= u64::MAX as f64); - - // Get number of nanoseconds. This should always fit in a u32, but check anyway. - let nanos = (secs.fract() * (NANOS_PER_SEC as f64)).trunc(); - assert!(nanos >= 0.0 && nanos <= u32::MAX as f64); - - Duration::new(whole_secs as u64, nanos as u32) -}