Skip to content

Commit 43ace2f

Browse files
committed
With fxhash everywhere
1 parent c1d0c4a commit 43ace2f

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/accelerate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::collections::HashMap;
21
use std::sync::atomic::{AtomicUsize, Ordering};
32

3+
use fxhash::FxHashMap;
44
use parking_lot::{MappedRwLockReadGuard, Mutex, RwLock, RwLockReadGuard};
55

66
/// The global list of currently alive accelerators.
@@ -12,7 +12,7 @@ static ID: AtomicUsize = AtomicUsize::new(0);
1212
/// The type of each individual accelerator.
1313
///
1414
/// Maps from call hashes to return hashes.
15-
type Accelerator = Mutex<HashMap<u128, u128>>;
15+
type Accelerator = Mutex<FxHashMap<u128, u128>>;
1616

1717
/// Generate a new accelerator.
1818
pub fn id() -> usize {
@@ -58,6 +58,6 @@ pub fn get(id: usize) -> Option<MappedRwLockReadGuard<'static, Accelerator>> {
5858
fn resize(len: usize) {
5959
let mut pair = ACCELERATORS.write();
6060
if len > pair.1.len() {
61-
pair.1.resize_with(len, || Mutex::new(HashMap::new()));
61+
pair.1.resize_with(len, || Mutex::new(FxHashMap::default()));
6262
}
6363
}

src/calltree.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::collections::HashMap;
21
use std::collections::hash_map::Entry;
32
use std::fmt::{self, Debug};
43
use std::hash::Hash;
54

5+
use fxhash::FxHashMap;
66
use 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

2121
impl<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

Comments
 (0)