Skip to content

Commit

Permalink
Use get_or_init and FxHasher
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Jul 2, 2024
1 parent 88a3125 commit 5c82e4d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions crates/turbo-tasks-memory/src/task_statistics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::sync::{Arc, OnceLock};
use std::{
hash::BuildHasherDefault,
sync::{Arc, OnceLock},
};

use dashmap::DashMap;
use rustc_hash::FxHasher;
use serde::{ser::SerializeMap, Serialize, Serializer};
use turbo_tasks::{registry, FunctionId};

Expand All @@ -12,11 +16,11 @@ pub struct TaskStatisticsApi {

impl TaskStatisticsApi {
pub fn enable(&self) -> &Arc<TaskStatistics> {
// ignore error: potentially already initialized, that's okay
let _ = self.inner.set(Arc::new(TaskStatistics {
inner: DashMap::new(),
}));
self.inner.get().unwrap()
self.inner.get_or_init(|| {
Arc::new(TaskStatistics {
inner: DashMap::with_hasher(Default::default()),
})
})
}

pub fn is_enabled(&self) -> bool {
Expand All @@ -39,7 +43,7 @@ impl TaskStatisticsApi {
/// A type representing the enabled state of [`TaskStatisticsApi`]. Implements
/// [`serde::Serialize`].
pub struct TaskStatistics {
inner: DashMap<FunctionId, TaskFunctionStatistics>,
inner: DashMap<FunctionId, TaskFunctionStatistics, BuildHasherDefault<FxHasher>>,
}

impl TaskStatistics {
Expand Down

0 comments on commit 5c82e4d

Please sign in to comment.