Skip to content

Commit 35522a9

Browse files
committed
Don't call Duration::new unnecessarily in Duration::from_secs
1 parent c7716d5 commit 35522a9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

library/core/src/time.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ const DAYS_PER_WEEK: u64 = 7;
4343
#[rustc_layout_scalar_valid_range_end(999_999_999)]
4444
struct Nanoseconds(u32);
4545

46+
impl Nanoseconds {
47+
// SAFETY: 0 is within the valid range
48+
const ZERO: Self = unsafe { Nanoseconds(0) };
49+
}
50+
4651
impl Default for Nanoseconds {
4752
#[inline]
4853
fn default() -> Self {
49-
// SAFETY: 0 is within the valid range
50-
unsafe { Nanoseconds(0) }
54+
Self::ZERO
5155
}
5256
}
5357

@@ -236,7 +240,7 @@ impl Duration {
236240
#[inline]
237241
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
238242
pub const fn from_secs(secs: u64) -> Duration {
239-
Duration::new(secs, 0)
243+
Duration { secs, nanos: Nanoseconds::ZERO }
240244
}
241245

242246
/// Creates a new `Duration` from the specified number of milliseconds.

0 commit comments

Comments
 (0)