`FxHashSet` uses a faster hashing algorithm than the default `SipHash`

This commit is contained in:
Greg Johnston 2022-12-01 17:22:35 -05:00
parent d266943a8f
commit a0e0194475
2 changed files with 6 additions and 4 deletions

View File

@ -15,6 +15,7 @@ gloo = "0.8"
js-sys = "0.3"
leptos_reactive = { path = "../leptos_reactive", default-features = false, version = "0.0.18" }
paste = "1"
rustc-hash = "1.1.0"
smallvec = "1"
tracing = "0.1"
typed-builder = "0.11"

View File

@ -2,9 +2,10 @@
use crate::{mount_child, MountKind, Mountable, RANGE};
use crate::{Comment, CoreComponent, IntoNode, Node};
use leptos_reactive::{create_effect, Scope};
use rustc_hash::FxHashSet;
use smallvec::SmallVec;
use std::{
borrow::Cow, cell::RefCell, collections::HashSet, hash::Hash, rc::Rc,
borrow::Cow, cell::RefCell, hash::Hash, rc::Rc,
};
use wasm_bindgen::JsCast;
@ -276,7 +277,7 @@ where
.iter()
.enumerate()
.map(|(idx, i)| HashKey(key_fn(i), idx))
.collect::<HashSet<_, _>>();
.collect::<FxHashSet<_>>();
if let Some(HashRun(prev_hash_run)) = prev_hash_run {
let cmds = diff(&prev_hash_run, &hashed_items);
@ -322,8 +323,8 @@ struct HashRun<T>(#[educe(Debug(ignore))] T);
/// Calculates the operations need to get from `a` to `b`.
fn diff<K: Eq + Hash>(
from: &HashSet<HashKey<K>>,
to: &HashSet<HashKey<K>>,
from: &FxHashSet<HashKey<K>>,
to: &FxHashSet<HashKey<K>>,
) -> Diff {
if to.is_empty() {
return Diff {