@@ -177,6 +177,7 @@ pub struct PhfStrSet {
177177 pub key : u64 ,
178178 pub disps : & ' static [ ( u32 , u32 ) ] ,
179179 pub atoms : & ' static [ & ' static str ] ,
180+ pub hashes : & ' static [ u32 ] ,
180181}
181182
182183pub struct EmptyStaticAtomSet ;
@@ -189,6 +190,8 @@ impl StaticAtomSet for EmptyStaticAtomSet {
189190 key : 0 ,
190191 disps : & [ ( 0 , 0 ) ] ,
191192 atoms : & [ "" ] ,
193+ // "" SipHash'd, and xored with u64_hash_to_u32.
194+ hashes : & [ 0x3ddddef3 ] ,
192195 } ;
193196 & SET
194197 }
@@ -219,14 +222,37 @@ impl<Static: StaticAtomSet> HeapSizeOf for Atom<Static> {
219222 }
220223}
221224
225+ impl < Static : StaticAtomSet > :: precomputed_hash:: PrecomputedHash for Atom < Static > {
226+ fn precomputed_hash ( & self ) -> u32 {
227+ self . get_hash ( )
228+ }
229+ }
230+
231+ fn u64_hash_as_u32 ( h : u64 ) -> u32 {
232+ // This may or may not be great...
233+ ( ( h >> 32 ) ^ h) as u32
234+ }
235+
222236impl < Static : StaticAtomSet > Atom < Static > {
223237 #[ inline( always) ]
224238 unsafe fn unpack ( & self ) -> UnpackedAtom {
225239 UnpackedAtom :: from_packed ( self . unsafe_data )
226240 }
227241
228242 pub fn get_hash ( & self ) -> u32 {
229- ( ( self . unsafe_data >> 32 ) ^ self . unsafe_data ) as u32
243+ match unsafe { self . unpack ( ) } {
244+ Static ( index) => {
245+ let static_set = Static :: get ( ) ;
246+ static_set. hashes [ index as usize ]
247+ }
248+ Dynamic ( entry) => {
249+ let entry = entry as * mut StringCacheEntry ;
250+ u64_hash_as_u32 ( unsafe { ( * entry) . hash } )
251+ }
252+ Inline ( ..) => {
253+ u64_hash_as_u32 ( self . unsafe_data )
254+ }
255+ }
230256 }
231257}
232258
0 commit comments