Skip to content

Commit 3e4bcee

Browse files
committed
Inline more things in cap_primitives::time.
1 parent 4b53247 commit 3e4bcee

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

cap-primitives/src/time/instant.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ impl Add<Duration> for Instant {
9292
///
9393
/// This function may panic if the resulting point in time cannot be represented by the
9494
/// underlying data structure. See [`Instant::checked_add`] for a version without panic.
95+
#[inline]
9596
fn add(self, other: Duration) -> Self {
9697
self.checked_add(other)
9798
.expect("overflow when adding duration to instant")
9899
}
99100
}
100101

101102
impl AddAssign<Duration> for Instant {
103+
#[inline]
102104
fn add_assign(&mut self, other: Duration) {
103105
*self = *self + other;
104106
}
@@ -107,13 +109,15 @@ impl AddAssign<Duration> for Instant {
107109
impl Sub<Duration> for Instant {
108110
type Output = Self;
109111

112+
#[inline]
110113
fn sub(self, other: Duration) -> Self {
111114
self.checked_sub(other)
112115
.expect("overflow when subtracting duration from instant")
113116
}
114117
}
115118

116119
impl SubAssign<Duration> for Instant {
120+
#[inline]
117121
fn sub_assign(&mut self, other: Duration) {
118122
*self = *self - other;
119123
}
@@ -122,6 +126,7 @@ impl SubAssign<Duration> for Instant {
122126
impl Sub<Instant> for Instant {
123127
type Output = Duration;
124128

129+
#[inline]
125130
fn sub(self, other: Self) -> Duration {
126131
self.duration_since(other)
127132
}

cap-primitives/src/time/monotonic_clock.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl MonotonicClock {
1515
/// # Safety
1616
///
1717
/// This is unsafe because access to clocks is an ambient authority.
18+
#[inline]
1819
pub unsafe fn new() -> Self {
1920
Self(())
2021
}
@@ -24,6 +25,7 @@ impl MonotonicClock {
2425
/// This corresponds to [`Instant::now`].
2526
///
2627
/// [`Instant::now`]: https://doc.rust-lang.org/std/time/struct.Instant.html#method.now
28+
#[inline]
2729
pub fn now(&self) -> Instant {
2830
Instant::from_std(time::Instant::now())
2931
}
@@ -33,6 +35,7 @@ impl MonotonicClock {
3335
/// This corresponds to [`Instant::elapsed`].
3436
///
3537
/// [`Instant::elapsed`]: https://doc.rust-lang.org/std/time/struct.Instant.html#method.elapsed
38+
#[inline]
3639
pub fn elapsed(&self, instant: Instant) -> Duration {
3740
instant.std.elapsed()
3841
}

cap-primitives/src/time/system_clock.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl SystemClock {
2626
/// # Safety
2727
///
2828
/// This is unsafe because access to clocks is an ambient authority.
29+
#[inline]
2930
pub unsafe fn new() -> Self {
3031
Self(())
3132
}
@@ -35,6 +36,7 @@ impl SystemClock {
3536
/// This corresponds to [`SystemTime::now`].
3637
///
3738
/// [`SystemTime::now`]: https://doc.rust-lang.org/std/time/struct.SystemTime.html#method.now
39+
#[inline]
3840
pub fn now(&self) -> SystemTime {
3941
SystemTime::from_std(time::SystemTime::now())
4042
}
@@ -44,6 +46,7 @@ impl SystemClock {
4446
/// This corresponds to [`SystemTime::elapsed`].
4547
///
4648
/// [`SystemTime::elapsed`]: https://doc.rust-lang.org/std/time/struct.SystemTime.html#method.elapsed
49+
#[inline]
4750
pub fn elapsed(&self, system_time: SystemTime) -> Result<Duration, SystemTimeError> {
4851
system_time.std.elapsed()
4952
}

cap-primitives/src/time/system_time.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ impl Add<Duration> for SystemTime {
9898
///
9999
/// This function may panic if the resulting point in time cannot be represented by the
100100
/// underlying data structure. See [`SystemTime::checked_add`] for a version without panic.
101+
#[inline]
101102
fn add(self, dur: Duration) -> Self {
102103
self.checked_add(dur)
103104
.expect("overflow when adding duration to instant")
104105
}
105106
}
106107

107108
impl AddAssign<Duration> for SystemTime {
109+
#[inline]
108110
fn add_assign(&mut self, other: Duration) {
109111
*self = *self + other;
110112
}
@@ -113,13 +115,15 @@ impl AddAssign<Duration> for SystemTime {
113115
impl Sub<Duration> for SystemTime {
114116
type Output = Self;
115117

118+
#[inline]
116119
fn sub(self, dur: Duration) -> Self {
117120
self.checked_sub(dur)
118121
.expect("overflow when subtracting duration from instant")
119122
}
120123
}
121124

122125
impl SubAssign<Duration> for SystemTime {
126+
#[inline]
123127
fn sub_assign(&mut self, other: Duration) {
124128
*self = *self - other;
125129
}

0 commit comments

Comments
 (0)