Don't call Duration::new unnecessarily in Duration::from_secs
This commit is contained in:
parent
c7716d5431
commit
35522a9e09
@ -43,11 +43,15 @@ const DAYS_PER_WEEK: u64 = 7;
|
|||||||
#[rustc_layout_scalar_valid_range_end(999_999_999)]
|
#[rustc_layout_scalar_valid_range_end(999_999_999)]
|
||||||
struct Nanoseconds(u32);
|
struct Nanoseconds(u32);
|
||||||
|
|
||||||
|
impl Nanoseconds {
|
||||||
|
// SAFETY: 0 is within the valid range
|
||||||
|
const ZERO: Self = unsafe { Nanoseconds(0) };
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for Nanoseconds {
|
impl Default for Nanoseconds {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
// SAFETY: 0 is within the valid range
|
Self::ZERO
|
||||||
unsafe { Nanoseconds(0) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +240,7 @@ impl Duration {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
|
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
|
||||||
pub const fn from_secs(secs: u64) -> Duration {
|
pub const fn from_secs(secs: u64) -> Duration {
|
||||||
Duration::new(secs, 0)
|
Duration { secs, nanos: Nanoseconds::ZERO }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `Duration` from the specified number of milliseconds.
|
/// Creates a new `Duration` from the specified number of milliseconds.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user