about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNoa <coolreader18@gmail.com>2024-05-17 14:26:50 -0500
committerNoa <coolreader18@gmail.com>2024-05-17 14:26:50 -0500
commit35522a9e0916aa5f5912299cc71c85716def7009 (patch)
tree4116ef2c88b4c11e390dfc67009ff6a8208b5b8d
parentc7716d543191e52ed817b725f2fab54bbd5d2707 (diff)
downloadrust-35522a9e0916aa5f5912299cc71c85716def7009.tar.gz
rust-35522a9e0916aa5f5912299cc71c85716def7009.zip
Don't call Duration::new unnecessarily in Duration::from_secs
-rw-r--r--library/core/src/time.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/library/core/src/time.rs b/library/core/src/time.rs
index 72f6a3b773b..0ddc0f22132 100644
--- a/library/core/src/time.rs
+++ b/library/core/src/time.rs
@@ -43,11 +43,15 @@ const DAYS_PER_WEEK: u64 = 7;
 #[rustc_layout_scalar_valid_range_end(999_999_999)]
 struct Nanoseconds(u32);
 
+impl Nanoseconds {
+    // SAFETY: 0 is within the valid range
+    const ZERO: Self = unsafe { Nanoseconds(0) };
+}
+
 impl Default for Nanoseconds {
     #[inline]
     fn default() -> Self {
-        // SAFETY: 0 is within the valid range
-        unsafe { Nanoseconds(0) }
+        Self::ZERO
     }
 }
 
@@ -236,7 +240,7 @@ impl Duration {
     #[inline]
     #[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
     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.