Skip to content

Commit

Permalink
refactor(hstr): Remove needless operations (#9964)
Browse files Browse the repository at this point in the history
**Description:**

We don't have an atom store merging API, so we don't need this code.
  • Loading branch information
kdy1 authored Jan 26, 2025
1 parent bc61c13 commit 6f781d8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
9 changes: 0 additions & 9 deletions crates/hstr/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use std::{
borrow::Cow,
fmt::Debug,
hash::{BuildHasherDefault, Hash, Hasher},
num::NonZeroU32,
ptr::NonNull,
sync::atomic::{AtomicU32, Ordering::SeqCst},
};

use rustc_hash::FxHasher;
Expand All @@ -19,7 +17,6 @@ use crate::{
pub(crate) struct Entry {
pub string: Box<str>,
pub hash: u64,
pub store_id: Option<NonZeroU32>,
}

impl Entry {
Expand Down Expand Up @@ -61,16 +58,12 @@ impl Hash for Entry {
/// # Merging [AtomStore]
#[derive(Debug)]
pub struct AtomStore {
pub(crate) id: Option<NonZeroU32>,
pub(crate) data: hashbrown::HashMap<Arc<Entry>, (), BuildEntryHasher>,
}

impl Default for AtomStore {
fn default() -> Self {
static ATOM_STORE_ID: AtomicU32 = AtomicU32::new(1);

Self {
id: Some(unsafe { NonZeroU32::new_unchecked(ATOM_STORE_ID.fetch_add(1, SeqCst)) }),
data: hashbrown::HashMap::with_capacity_and_hasher(64, Default::default()),
}
}
Expand Down Expand Up @@ -122,7 +115,6 @@ pub(crate) trait Storage {
impl Storage for &'_ mut AtomStore {
#[inline(never)]
fn insert_entry(self, text: Cow<str>, hash: u64) -> Arc<Entry> {
let store_id = self.id;
let (entry, _) = self
.data
.raw_entry_mut()
Expand All @@ -132,7 +124,6 @@ impl Storage for &'_ mut AtomStore {
Arc::new(Entry {
string: text.into_owned().into_boxed_str(),
hash,
store_id,
}),
(),
)
Expand Down
20 changes: 3 additions & 17 deletions crates/hstr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ macro_rules! atom {
($s:tt) => {{
#[inline(never)]
fn get_atom() -> $crate::Atom {
thread_local! {
static CACHE: $crate::Atom = $crate::Atom::from($s);
}
CACHE.with(|cache| $crate::Atom::clone(cache))
static CACHE: $crate::CachedAtom = $crate::CachedAtom::new(|| $crate::Atom::from($s));

(*CACHE).clone()
}

get_atom()
Expand Down Expand Up @@ -285,19 +284,6 @@ impl PartialEq for Atom {
return false;
}

// If the store is the same, the same string has same `unsafe_data``
match (&te.store_id, &oe.store_id) {
(Some(this_store), Some(other_store)) => {
if this_store == other_store {
return false;
}
}
(None, None) => {
return false;
}
_ => {}
}

return te.string == oe.string;
}

Expand Down

0 comments on commit 6f781d8

Please sign in to comment.