From dcd06c14a63c5846ae833f2751c3b94b79d8977a Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Tue, 10 Sep 2024 16:18:59 +0100 Subject: [PATCH] Remove parking_lot dependency std::sync::Mutex now has comparable performance --- Cargo.toml | 1 - src/dynamic_set.rs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index df159f1..a67ed94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,6 @@ once_cell = "1.10.0" serde = { version = "1", optional = true } phf_shared = "0.11" new_debug_unreachable = "1.0.2" -parking_lot = "0.12" [[test]] name = "small-stack" diff --git a/src/dynamic_set.rs b/src/dynamic_set.rs index 46e7a54..40cea41 100644 --- a/src/dynamic_set.rs +++ b/src/dynamic_set.rs @@ -8,12 +8,12 @@ // except according to those terms. use once_cell::sync::Lazy; -use parking_lot::Mutex; use std::borrow::Cow; use std::mem; use std::ptr::NonNull; use std::sync::atomic::AtomicIsize; use std::sync::atomic::Ordering::SeqCst; +use std::sync::Mutex; const NB_BUCKETS: usize = 1 << 12; // 4096 const BUCKET_MASK: u32 = (1 << 12) - 1; @@ -52,7 +52,7 @@ pub(crate) static DYNAMIC_SET: Lazy = Lazy::new(|| { impl Set { pub(crate) fn insert(&self, string: Cow, hash: u32) -> NonNull { let bucket_index = (hash & BUCKET_MASK) as usize; - let mut linked_list = self.buckets[bucket_index].lock(); + let mut linked_list = self.buckets[bucket_index].lock().unwrap(); { let mut ptr: Option<&mut Box> = linked_list.as_mut(); @@ -90,7 +90,7 @@ impl Set { let value: &Entry = unsafe { &*ptr }; let bucket_index = (value.hash & BUCKET_MASK) as usize; - let mut linked_list = self.buckets[bucket_index].lock(); + let mut linked_list = self.buckets[bucket_index].lock().unwrap(); debug_assert!(value.ref_count.load(SeqCst) == 0); let mut current: &mut Option> = &mut linked_list;