Skip to content

Commit

Permalink
replace manual time convertions with std ones
Browse files Browse the repository at this point in the history
  • Loading branch information
klensy committed Nov 3, 2024
1 parent db034ce commit be3a635
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
18 changes: 6 additions & 12 deletions compiler/rustc_incremental/src/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,23 +585,17 @@ fn extract_timestamp_from_session_dir(directory_name: &str) -> Result<SystemTime

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

fn string_to_timestamp(s: &str) -> Result<SystemTime, &'static str> {
let micros_since_unix_epoch = u64::from_str_radix(s, INT_ENCODE_BASE as u32);

if micros_since_unix_epoch.is_err() {
return Err("timestamp not an int");
}

let micros_since_unix_epoch = micros_since_unix_epoch.unwrap();
let micros_since_unix_epoch = match u64::from_str_radix(s, INT_ENCODE_BASE as u32) {
Ok(micros) => micros,
Err(_) => return Err("timestamp not an int"),
};

let duration = Duration::new(
micros_since_unix_epoch / 1_000_000,
1000 * (micros_since_unix_epoch % 1_000_000) as u32,
);
let duration = Duration::from_micros(micros_since_unix_epoch);
Ok(UNIX_EPOCH + duration)
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ impl<D: Deps> CurrentDepGraph<D> {
use std::time::{SystemTime, UNIX_EPOCH};

let duration = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let nanos = duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64;
let nanos = duration.as_nanos();
let mut stable_hasher = StableHasher::new();
nanos.hash(&mut stable_hasher);
let anon_id_seed = stable_hasher.finish();
Expand Down

0 comments on commit be3a635

Please sign in to comment.