Skip to content

Commit e25b4c6

Browse files
committed
Keep a u32 hash rather than u64 in dynamic_atoms_map::Entry, since that’s all we ever use
1 parent b5174ea commit e25b4c6

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/atom.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<Static: StaticAtomSet> Atom<Static> {
222222
}
223223
Dynamic(entry) => {
224224
let entry = entry as *mut Entry;
225-
u64_hash_as_u32(unsafe { (*entry).hash })
225+
unsafe { (*entry).hash }
226226
}
227227
Inline(..) => u64_hash_as_u32(self.unsafe_data.get()),
228228
}
@@ -280,8 +280,12 @@ impl<'a, Static: StaticAtomSet> From<Cow<'a, str>> for Atom<Static> {
280280
buf[..len].copy_from_slice(string_to_add.as_bytes());
281281
Inline(len as u8, buf)
282282
} else {
283-
let hash = (hash.g as u64) << 32 | (hash.f1 as u64);
284-
Dynamic(DYNAMIC_SET.lock().unwrap().insert(string_to_add, hash) as *mut ())
283+
Dynamic(
284+
DYNAMIC_SET
285+
.lock()
286+
.unwrap()
287+
.insert(string_to_add, hash.g) as *mut (),
288+
)
285289
}
286290
};
287291

src/dynamic_set.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ use std::sync::atomic::Ordering::SeqCst;
1515
use std::sync::Mutex;
1616

1717
const NB_BUCKETS: usize = 1 << 12; // 4096
18-
const BUCKET_MASK: u64 = (1 << 12) - 1;
18+
const BUCKET_MASK: u32 = (1 << 12) - 1;
1919

2020
pub(crate) struct Set {
2121
buckets: Box<[Option<Box<Entry>>; NB_BUCKETS]>,
2222
}
2323

2424
pub(crate) struct Entry {
2525
pub(crate) string: Box<str>,
26-
pub(crate) hash: u64,
26+
pub(crate) hash: u32,
2727
pub(crate) ref_count: AtomicIsize,
2828
next_in_bucket: Option<Box<Entry>>,
2929
}
@@ -49,7 +49,7 @@ lazy_static! {
4949
}
5050

5151
impl Set {
52-
pub(crate) fn insert(&mut self, string: Cow<str>, hash: u64) -> *mut Entry {
52+
pub(crate) fn insert(&mut self, string: Cow<str>, hash: u32) -> *mut Entry {
5353
let bucket_index = (hash & BUCKET_MASK) as usize;
5454
{
5555
let mut ptr: Option<&mut Box<Entry>> = self.buckets[bucket_index].as_mut();

0 commit comments

Comments
 (0)