1- use core:: { hash:: BuildHasher , time:: Duration } ;
1+ use core:: {
2+ hash:: { Hash , Hasher } ,
3+ time:: Duration ,
4+ } ;
25
36use alloc:: { boxed:: Box , format, vec} ;
47
58use dyn_clone:: clone_box;
6- use hashbrown:: DefaultHashBuilder ;
79use java_class_proto:: JavaMethodProto ;
810use java_constants:: MethodAccessFlags ;
911use jvm:: { ClassInstance , ClassInstanceRef , Jvm , Result , runtime:: JavaLangString } ;
@@ -13,6 +15,27 @@ use crate::{Runtime, RuntimeClassProto, RuntimeContext, SpawnCallback, classes::
1315// class java.lang.Object
1416pub struct Object ;
1517
18+ const FNV_OFFSET_BASIS_64 : u64 = 0xcbf29ce484222325 ;
19+ const FNV_PRIME_64 : u64 = 0x100000001b3 ;
20+
21+ #[ derive( Default ) ]
22+ struct IdentityHasher ( u64 ) ;
23+
24+ impl Hasher for IdentityHasher {
25+ fn finish ( & self ) -> u64 {
26+ self . 0
27+ }
28+
29+ fn write ( & mut self , bytes : & [ u8 ] ) {
30+ let mut hash = if self . 0 == 0 { FNV_OFFSET_BASIS_64 } else { self . 0 } ;
31+ for byte in bytes {
32+ hash ^= u64:: from ( * byte) ;
33+ hash = hash. wrapping_mul ( FNV_PRIME_64 ) ;
34+ }
35+ self . 0 = hash;
36+ }
37+ }
38+
1639impl Object {
1740 pub fn as_proto ( ) -> RuntimeClassProto {
1841 RuntimeClassProto {
@@ -61,7 +84,9 @@ impl Object {
6184
6285 let rust_this: Box < dyn ClassInstance > = this. into ( ) ;
6386
64- let hash = DefaultHashBuilder :: default ( ) . hash_one ( & rust_this) ;
87+ let mut hasher = IdentityHasher :: default ( ) ;
88+ rust_this. hash ( & mut hasher) ;
89+ let hash = hasher. finish ( ) ;
6590
6691 Ok ( hash as _ )
6792 }
0 commit comments