Skip to content

Commit be3a635

Browse files
committed
replace manual time convertions with std ones
1 parent db034ce commit be3a635

File tree

2 files changed

+7
-13
lines changed
  • compiler
    • rustc_incremental/src/persist
    • rustc_query_system/src/dep_graph

2 files changed

+7
-13
lines changed

compiler/rustc_incremental/src/persist/fs.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -585,23 +585,17 @@ fn extract_timestamp_from_session_dir(directory_name: &str) -> Result<SystemTime
585585

586586
fn timestamp_to_string(timestamp: SystemTime) -> BaseNString {
587587
let duration = timestamp.duration_since(UNIX_EPOCH).unwrap();
588-
let micros = duration.as_secs() * 1_000_000 + (duration.subsec_nanos() as u64) / 1000;
588+
let micros: u64 = duration.as_micros().try_into().unwrap();
589589
micros.to_base_fixed_len(CASE_INSENSITIVE)
590590
}
591591

592592
fn string_to_timestamp(s: &str) -> Result<SystemTime, &'static str> {
593-
let micros_since_unix_epoch = u64::from_str_radix(s, INT_ENCODE_BASE as u32);
594-
595-
if micros_since_unix_epoch.is_err() {
596-
return Err("timestamp not an int");
597-
}
598-
599-
let micros_since_unix_epoch = micros_since_unix_epoch.unwrap();
593+
let micros_since_unix_epoch = match u64::from_str_radix(s, INT_ENCODE_BASE as u32) {
594+
Ok(micros) => micros,
595+
Err(_) => return Err("timestamp not an int"),
596+
};
600597

601-
let duration = Duration::new(
602-
micros_since_unix_epoch / 1_000_000,
603-
1000 * (micros_since_unix_epoch % 1_000_000) as u32,
604-
);
598+
let duration = Duration::from_micros(micros_since_unix_epoch);
605599
Ok(UNIX_EPOCH + duration)
606600
}
607601

compiler/rustc_query_system/src/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ impl<D: Deps> CurrentDepGraph<D> {
10981098
use std::time::{SystemTime, UNIX_EPOCH};
10991099

11001100
let duration = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
1101-
let nanos = duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64;
1101+
let nanos = duration.as_nanos();
11021102
let mut stable_hasher = StableHasher::new();
11031103
nanos.hash(&mut stable_hasher);
11041104
let anon_id_seed = stable_hasher.finish();

0 commit comments

Comments
 (0)