diff --git a/src/collections/string_pool.rs b/src/collections/string_pool.rs index 5cd82b91d55b8ebff11b98bd504745ceb5d1616d..30cb8a5c6451ca390b91ed9c5a3d93bf989a2406 100644 --- a/src/collections/string_pool.rs +++ b/src/collections/string_pool.rs @@ -1,7 +1,10 @@ use std::ptr::null_mut; +use std::collections::hash_map::DefaultHasher; +use std::hash::{Hash, Hasher}; const SLAB_SIZE: usize = u16::max_value() as usize; +#[derive(Clone)] pub struct StringRef { data: *const u8, length: usize, @@ -16,6 +19,22 @@ impl StringRef { } } +impl PartialEq for StringRef { + fn eq(&self, other: &StringRef) -> bool { + self.as_str() == other.as_str() + } +} + +impl Eq for StringRef {} + +impl Hash for StringRef { + fn hash(&self, state: &mut H) { + unsafe{ + state.write(std::slice::from_raw_parts(self.data, self.length)); + } + } +} + struct StringPoolSlab { prev: *mut StringPoolSlab, data: Vec, @@ -60,7 +79,7 @@ impl StringPool { last = unsafe{&mut *self.last}; } - // Must fit now + // Must fit now, compute hash and put in buffer debug_assert!(data_len <= last.remaining); let range_start = last.data.len(); last.data.extend_from_slice(data);