diff --git a/reactive_stores/src/lib.rs b/reactive_stores/src/lib.rs index 816636b84..af66655ba 100644 --- a/reactive_stores/src/lib.rs +++ b/reactive_stores/src/lib.rs @@ -60,20 +60,21 @@ impl TriggerMap { pub struct FieldKeys { spare_keys: Vec, current_key: usize, - keys: HashMap, + keys: FxHashMap, } impl FieldKeys where K: Debug + Hash + PartialEq + Eq, { - pub fn new(from_iter: impl IntoIterator) -> Self { - let mut current_key = 0; - let mut keys = HashMap::new(); - for (idx, key) in from_iter.into_iter().enumerate() { - let segment = current_key.into(); + pub fn new(from_keys: Vec) -> Self { + let mut keys = FxHashMap::with_capacity_and_hasher( + from_keys.len(), + Default::default(), + ); + for (idx, key) in from_keys.into_iter().enumerate() { + let segment = idx.into(); keys.insert(key, (segment, idx)); - current_key += 1; } Self { @@ -104,7 +105,7 @@ where .into_iter() .enumerate() .map(|(idx, key)| (key, idx)) - .collect::>(); + .collect::>(); // remove old keys and recycle the slots self.keys.retain(|key, old_entry| match new_keys.get(key) {