Skip to content

Commit 8c3b7ad

Browse files
committed
Elimitate type conversions NANOS_PER_SEC
1 parent 2cc05c8 commit 8c3b7ad

File tree

1 file changed

+5
-5
lines changed
  • intel-sgx/insecure-time/src

1 file changed

+5
-5
lines changed

intel-sgx/insecure-time/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use core::sync::atomic::{AtomicBool, AtomicU64, Ordering};
2525
use core::time::Duration;
2626
use core::ops::Add;
2727

28-
const NANOS_PER_SEC: u32 = 1_000_000_000;
28+
const NANOS_PER_SEC: u64 = 1_000_000_000;
2929

3030
pub trait NativeTime: PartialOrd + Copy + Add<core::time::Duration, Output = Self> + ToOwned {
3131
fn minimum() -> Self;
@@ -135,7 +135,7 @@ impl Ticks {
135135
pub fn from_duration(duration: Duration, freq: &Freq) -> Self {
136136
let freq = freq.as_u64();
137137
let ticks_secs = duration.as_secs() * freq;
138-
let ticks_nsecs = duration.subsec_nanos() as u64 * freq / NANOS_PER_SEC as u64;
138+
let ticks_nsecs = duration.subsec_nanos() as u64 * freq / NANOS_PER_SEC;
139139
Ticks::new(ticks_secs + ticks_nsecs)
140140
}
141141

@@ -144,7 +144,7 @@ impl Ticks {
144144
let ticks = self.0.load(Ordering::Relaxed);
145145

146146
let time_secs = ticks / freq;
147-
let time_nsecs = (ticks % freq * NANOS_PER_SEC as u64) / freq;
147+
let time_nsecs = (ticks % freq * NANOS_PER_SEC) / freq;
148148
let time_nsecs: u32 = time_nsecs.try_into().expect("must be smaller than 1sec");
149149

150150
Duration::new(time_secs, time_nsecs)
@@ -798,7 +798,7 @@ mod tests {
798798
type Output = RandTime;
799799

800800
fn add(self, other: Duration) -> Self::Output {
801-
let t = self.0 + other.as_secs() * super::NANOS_PER_SEC as u64 + other.subsec_nanos() as u64;
801+
let t = self.0 + other.as_secs() * super::NANOS_PER_SEC + other.subsec_nanos() as u64;
802802
RandTime(t)
803803
}
804804
}
@@ -829,7 +829,7 @@ mod tests {
829829
type Output = SgxTime;
830830

831831
fn add(self, other: Duration) -> Self::Output {
832-
let t = self.0 + other.as_secs() * super::NANOS_PER_SEC as u64 + other.subsec_nanos() as u64;
832+
let t = self.0 + other.as_secs() * super::NANOS_PER_SEC + other.subsec_nanos() as u64;
833833
SgxTime(t)
834834
}
835835
}

0 commit comments

Comments
 (0)