From dbd3dc1e9b79c8c30f6843fd80a25e871ffd5cee Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Wed, 4 Sep 2024 18:40:41 -0700 Subject: [PATCH] Switched to NoOpHash in FunctionMap Since ArgumentSignature is just a wrapper around Box<[Type]>, it should already contain a "high-quality hash" --- crates/bevy_reflect/src/func/function_map.rs | 29 ++++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/crates/bevy_reflect/src/func/function_map.rs b/crates/bevy_reflect/src/func/function_map.rs index 6a6942a93e..2fcf708d1f 100644 --- a/crates/bevy_reflect/src/func/function_map.rs +++ b/crates/bevy_reflect/src/func/function_map.rs @@ -1,7 +1,8 @@ use crate::func::signature::ArgumentSignature; use crate::func::{ArgList, FunctionError, FunctionInfo, FunctionInfoType, FunctionOverloadError}; use alloc::borrow::Cow; -use bevy_utils::HashMap; +use bevy_utils::hashbrown::HashMap; +use bevy_utils::NoOpHash; /// A helper type for storing a mapping of overloaded functions /// along with the corresponding [function information]. @@ -10,7 +11,11 @@ use bevy_utils::HashMap; #[derive(Clone, Debug)] pub(super) enum FunctionMap { Single(F, FunctionInfo), - Overloaded(Vec, Vec, HashMap), + Overloaded( + Vec, + Vec, + HashMap, + ), } impl FunctionMap { @@ -87,7 +92,7 @@ impl FunctionMap { Ok(Self::Overloaded( vec![self_func, other_func], vec![self_info, other_info], - HashMap::from([(self_sig, 0), (other_sig, 1)]), + HashMap::from_iter([(self_sig, 0), (other_sig, 1)]), )) } ( @@ -182,7 +187,7 @@ mod tests { assert_eq!(infos.len(), 2); assert_eq!( indices, - HashMap::from([ + HashMap::from_iter([ (ArgumentSignature::from_iter([Type::of::()]), 0), (ArgumentSignature::from_iter([Type::of::()]), 1), ]) @@ -198,7 +203,7 @@ mod tests { FunctionInfo::anonymous().with_arg::("arg0"), FunctionInfo::anonymous().with_arg::("arg0"), ], - HashMap::from([ + HashMap::from_iter([ (ArgumentSignature::from_iter([Type::of::()]), 0), (ArgumentSignature::from_iter([Type::of::()]), 1), ]), @@ -211,7 +216,7 @@ mod tests { assert_eq!(infos.len(), 3); assert_eq!( indices, - HashMap::from([ + HashMap::from_iter([ (ArgumentSignature::from_iter([Type::of::()]), 0), (ArgumentSignature::from_iter([Type::of::()]), 1), (ArgumentSignature::from_iter([Type::of::()]), 2), @@ -227,7 +232,7 @@ mod tests { FunctionInfo::anonymous().with_arg::("arg0"), FunctionInfo::anonymous().with_arg::("arg0"), ], - HashMap::from([ + HashMap::from_iter([ (ArgumentSignature::from_iter([Type::of::()]), 0), (ArgumentSignature::from_iter([Type::of::()]), 1), ]), @@ -241,7 +246,7 @@ mod tests { assert_eq!(infos.len(), 3); assert_eq!( indices, - HashMap::from([ + HashMap::from_iter([ (ArgumentSignature::from_iter([Type::of::()]), 0), (ArgumentSignature::from_iter([Type::of::()]), 1), (ArgumentSignature::from_iter([Type::of::()]), 2), @@ -257,7 +262,7 @@ mod tests { FunctionInfo::anonymous().with_arg::("arg0"), FunctionInfo::anonymous().with_arg::("arg0"), ], - HashMap::from([ + HashMap::from_iter([ (ArgumentSignature::from_iter([Type::of::()]), 0), (ArgumentSignature::from_iter([Type::of::()]), 1), ]), @@ -268,7 +273,7 @@ mod tests { FunctionInfo::anonymous().with_arg::("arg0"), FunctionInfo::anonymous().with_arg::("arg0"), ], - HashMap::from([ + HashMap::from_iter([ (ArgumentSignature::from_iter([Type::of::()]), 0), (ArgumentSignature::from_iter([Type::of::()]), 1), ]), @@ -281,7 +286,7 @@ mod tests { assert_eq!(infos.len(), 4); assert_eq!( indices, - HashMap::from([ + HashMap::from_iter([ (ArgumentSignature::from_iter([Type::of::()]), 0), (ArgumentSignature::from_iter([Type::of::()]), 1), (ArgumentSignature::from_iter([Type::of::()]), 2), @@ -304,7 +309,7 @@ mod tests { FunctionInfo::anonymous().with_arg::("arg0"), FunctionInfo::anonymous().with_arg::("arg1"), ], - HashMap::from([ + HashMap::from_iter([ ( ArgumentSignature::from_iter([Type::of::(), Type::of::()]), 0,