Removed FnvHash and transformed the rest to FxHashmap (#39233)

This should be the final PR for the Hash Function series that is
trivial.

Of note: I decided to transform `HashMapTracedValues<Atom,..>` to use
FxBuildHasher. This is likely not going to improve performance as Atom's
already have a unique u32 that is used as the Hash but it safes a few
bytes for the RandomState that is normally in the HashMap.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>

Testing: Hash function changes should not change functionality, we
slightly decrease the size and unit tests still work.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This commit is contained in:
Narfinger 2025-09-10 15:34:54 +02:00 committed by GitHub
parent 726b456120
commit 84465e7768
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
55 changed files with 211 additions and 202 deletions

View file

@ -29,8 +29,8 @@ use std::marker::PhantomData;
use std::rc::Rc;
use std::sync::{Arc, Weak};
use fnv::FnvHashMap;
use js::jsapi::JSTracer;
use rustc_hash::FxHashMap;
use script_bindings::script_runtime::CanGc;
use crate::dom::bindings::conversions::ToJSValConvertible;
@ -47,14 +47,14 @@ mod dummy {
use std::cell::RefCell;
use std::rc::Rc;
use fnv::{FnvBuildHasher, FnvHashMap};
use rustc_hash::FxHashMap;
use super::LiveDOMReferences;
thread_local!(pub(crate) static LIVE_REFERENCES: Rc<RefCell<LiveDOMReferences>> =
Rc::new(RefCell::new(
LiveDOMReferences {
reflectable_table: RefCell::new(FnvHashMap::with_hasher(FnvBuildHasher::new())),
promise_table: RefCell::new(FnvHashMap::with_hasher(FnvBuildHasher::new())),
reflectable_table: RefCell::new(FxHashMap::default()),
promise_table: RefCell::new(FxHashMap::default()),
}
)));
}
@ -232,8 +232,8 @@ impl<T: DomObject> Clone for Trusted<T> {
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
pub(crate) struct LiveDOMReferences {
// keyed on pointer to Rust DOM object
reflectable_table: RefCell<FnvHashMap<*const libc::c_void, Weak<TrustedReference>>>,
promise_table: RefCell<FnvHashMap<*const Promise, Vec<Rc<Promise>>>>,
reflectable_table: RefCell<FxHashMap<*const libc::c_void, Weak<TrustedReference>>>,
promise_table: RefCell<FxHashMap<*const Promise, Vec<Rc<Promise>>>>,
}
impl LiveDOMReferences {
@ -283,7 +283,7 @@ impl LiveDOMReferences {
}
/// Remove null entries from the live references table
fn remove_nulls<K: Eq + Hash + Clone, V>(table: &mut FnvHashMap<K, Weak<V>>) {
fn remove_nulls<K: Eq + Hash + Clone, V>(table: &mut FxHashMap<K, Weak<V>>) {
let to_remove: Vec<K> = table
.iter()
.filter(|&(_, value)| Weak::upgrade(value).is_none())