Skip to content

Commit

Permalink
simplify timestamp id, remove allocation. (#1223)
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Schleich authored Jul 5, 2024
1 parent b2df2b7 commit cae8697
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions zenoh/src/api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,15 @@ impl Session {
/// # }
/// ```
pub fn new_timestamp(&self) -> Timestamp {
let id = self.runtime.zid();
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().into(); // UNIX_EPOCH is Returns a Timespec::zero(), Unwrap Should be permissable here
Timestamp::new(now, id.into())
match self.hlc() {
Some(hlc) => hlc.new_timestamp(),
None => {
// Called in the case that the runtime is not initialized with an hlc
// UNIX_EPOCH is Returns a Timespec::zero(), Unwrap Should be permissable here
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().into();
Timestamp::new(now, self.runtime.zid().into())
}
}
}
}

Expand Down

0 comments on commit cae8697

Please sign in to comment.