mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Move util::time::duration_from_seconds to profile::time
This commit is contained in:
parent
f8f00fac5b
commit
5a576e873e
4 changed files with 16 additions and 24 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue