1- use std:: collections:: HashMap ;
21use std:: collections:: hash_map:: Entry ;
32use std:: fmt:: { self , Debug } ;
43use std:: hash:: Hash ;
54
5+ use fxhash:: FxHashMap ;
66use slab:: Slab ;
77
88/// A deduplicated sequence of calls to tracked functions.
@@ -13,15 +13,19 @@ pub struct CallSequence<C> {
1313 /// The raw calls. In order, but deduplicated via the `map`.
1414 vec : Vec < Option < ( C , u128 ) > > ,
1515 /// A map from hashes of calls to the indices in the vector.
16- map : HashMap < u128 , usize > ,
16+ map : FxHashMap < u128 , usize > ,
1717 /// A cursor for iteration in `Self::next`.
1818 cursor : usize ,
1919}
2020
2121impl < C > CallSequence < C > {
2222 /// Creates an empty sequence.
2323 pub fn new ( ) -> Self {
24- Self { vec : Vec :: new ( ) , map : HashMap :: new ( ) , cursor : 0 }
24+ Self {
25+ vec : Vec :: new ( ) ,
26+ map : FxHashMap :: default ( ) ,
27+ cursor : 0 ,
28+ }
2529 }
2630}
2731
@@ -103,11 +107,11 @@ pub struct CallTree<C, T> {
103107 /// Leaf nodes, directly storing outputs.
104108 leaves : Slab < LeafNode < T > > ,
105109 /// The initial node for the given key hash.
106- start : HashMap < u128 , NodeId > ,
110+ start : FxHashMap < u128 , NodeId > ,
107111 /// Maps from parent nodes to child nodes. The key is a pair of an inner
108112 /// node ID and a return hash for that call. The value is the node to
109113 /// transition to.
110- edges : HashMap < ( InnerId , u128 ) , NodeId > ,
114+ edges : FxHashMap < ( InnerId , u128 ) , NodeId > ,
111115}
112116
113117/// An inner node in the call tree.
@@ -135,8 +139,8 @@ impl<C, T> CallTree<C, T> {
135139 Self {
136140 inner : Slab :: new ( ) ,
137141 leaves : Slab :: new ( ) ,
138- edges : HashMap :: new ( ) ,
139- start : HashMap :: new ( ) ,
142+ edges : FxHashMap :: default ( ) ,
143+ start : FxHashMap :: default ( ) ,
140144 }
141145 }
142146}
@@ -459,7 +463,7 @@ mod tests {
459463 T : Debug + PartialEq + Clone ,
460464 {
461465 let mut tree = CallTree :: new ( ) ;
462- let mut kept = Vec :: < ( u128 , HashMap < C , u128 > , T ) > :: new ( ) ;
466+ let mut kept = Vec :: < ( u128 , FxHashMap < C , u128 > , T ) > :: new ( ) ;
463467 let mut ignore_insert_errors = false ;
464468
465469 for op in ops {
0 commit comments