Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ name = "string_cache"

[features]
serde_support = ["serde"]
default = ["serde_support"]

default = ["serde_support", "parking_lot_support"]
parking_lot_support = ["parking_lot"]
[dependencies]
precomputed-hash = "0.1"
once_cell = "1.10.0"
serde = { version = "1", optional = true }
phf_shared = "0.10"
new_debug_unreachable = "1.0.2"
parking_lot = "0.12"
parking_lot = { version = "0.12", optional = true}

[[test]]
name = "small-stack"
Expand Down
11 changes: 11 additions & 0 deletions src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,13 @@ impl<'a, Static: StaticAtomSet> From<Cow<'a, str>> for Atom<Static> {
phantom: PhantomData,
}
} else {
#[cfg(feature = "parking_lot_support")]
let ptr: std::ptr::NonNull<Entry> =
DYNAMIC_SET.lock().insert(string_to_add, hash.g);

#[cfg(not(feature = "parking_lot_support"))]
let ptr: std::ptr::NonNull<Entry> =
DYNAMIC_SET.lock().unwrap().insert(string_to_add, hash.g);
let data = ptr.as_ptr() as u64;
debug_assert!(0 == data & TAG_MASK);
Atom {
Expand Down Expand Up @@ -237,6 +242,12 @@ impl<Static> Drop for Atom<Static> {

// Out of line to guide inlining.
fn drop_slow<Static>(this: &mut Atom<Static>) {
#[cfg(not(feature = "parking_lot_support"))]
DYNAMIC_SET
.lock()
.unwrap()
.remove(this.unsafe_data.get() as *mut Entry);
#[cfg(feature = "parking_lot_support")]
DYNAMIC_SET
.lock()
.remove(this.unsafe_data.get() as *mut Entry);
Expand Down
3 changes: 3 additions & 0 deletions src/dynamic_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
// except according to those terms.

use once_cell::sync::Lazy;
#[cfg(feature = "parking_lot_support")]
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;
#[cfg(not(feature = "parking_lot_support"))]
use std::sync::Mutex;

const NB_BUCKETS: usize = 1 << 12; // 4096
const BUCKET_MASK: u32 = (1 << 12) - 1;
Expand Down