@@ -18,24 +18,21 @@ use buck2_util::arc_str::ArcSlice;
18
18
use buck2_util:: arc_str:: ArcStr ;
19
19
use buck2_util:: hash:: BuckHasher ;
20
20
use dupe:: Dupe ;
21
- use hashbrown:: raw :: RawTable ;
21
+ use hashbrown:: HashTable ;
22
22
23
23
/// An interner specific to our AttrCoercionContext used for interning different kinds of attributes.
24
24
/// Things specific about this interner:
25
25
/// - Requires interned values to be Dupe, so that you can intern both Arc<...> and specific Arc types like ArcStr.
26
26
/// - Interner is not static, so it's not required to take up memory for the entire duration of the program.
27
27
pub ( crate ) struct AttrCoercionInterner < T : Dupe + Hash + Eq , H = BuckHasher > {
28
- /// We use `RawTable` where because `HashMap` API
29
- /// requires either computing hash twice (for get, then for insert) or
30
- /// allocating a key to perform a query using `entry` API.
31
- cache : RefCell < RawTable < ( u64 , T ) > > ,
28
+ cache : RefCell < HashTable < ( u64 , T ) > > ,
32
29
_marker : marker:: PhantomData < H > ,
33
30
}
34
31
35
32
impl < T : Dupe + Hash + Eq , H : Hasher + Default > AttrCoercionInterner < T , H > {
36
33
pub ( crate ) fn new ( ) -> Self {
37
34
Self {
38
- cache : RefCell :: new ( RawTable :: new ( ) ) ,
35
+ cache : RefCell :: new ( HashTable :: new ( ) ) ,
39
36
_marker : marker:: PhantomData ,
40
37
}
41
38
}
@@ -49,12 +46,12 @@ impl<T: Dupe + Hash + Eq, H: Hasher + Default> AttrCoercionInterner<T, H> {
49
46
let hash = compute_hash ( & internable, H :: default ( ) ) ;
50
47
let mut cache = self . cache . borrow_mut ( ) ;
51
48
52
- if let Some ( ( _h, v) ) = cache. get ( hash, |( _h, v) | internable. equivalent ( v) ) {
49
+ if let Some ( ( _h, v) ) = cache. find ( hash, |( _h, v) | internable. equivalent ( v) ) {
53
50
return v. dupe ( ) ;
54
51
}
55
52
56
53
let value: T = internable. into ( ) ;
57
- cache. insert ( hash, ( hash, value. dupe ( ) ) , |( h, _v) | * h) ;
54
+ cache. insert_unique ( hash, ( hash, value. dupe ( ) ) , |( h, _v) | * h) ;
58
55
value
59
56
}
60
57
}
0 commit comments