From 2e83e3614668823c70039aeafe5f55e82d6bc073 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 28 Sep 2021 17:56:24 +0200 Subject: [PATCH] Use ahash for Id and other things that need hashing --- egui/src/id.rs | 14 ++++---------- epaint/src/util.rs | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/egui/src/id.rs b/egui/src/id.rs index ce641fc6..5e4367bb 100644 --- a/egui/src/id.rs +++ b/egui/src/id.rs @@ -1,7 +1,5 @@ // TODO: have separate types `PositionId` and `UniqueId`. ? -use std::hash::Hash; - /// egui tracks widgets frame-to-frame using `Id`s. /// /// For instance, if you start dragging a slider one frame, egui stores @@ -37,21 +35,17 @@ impl Id { } /// Generate a new `Id` by hashing some source (e.g. a string or integer). - pub fn new(source: impl Hash) -> Id { - // NOTE: AHasher is NOT suitable for this! - use std::collections::hash_map::DefaultHasher; + pub fn new(source: impl std::hash::Hash) -> Id { use std::hash::Hasher; - let mut hasher = DefaultHasher::default(); + let mut hasher = epaint::ahash::AHasher::new_with_keys(123, 456); source.hash(&mut hasher); Id(hasher.finish()) } /// Generate a new `Id` by hashing the parent `Id` and the given argument. - pub fn with(self, child: impl Hash) -> Id { - // NOTE: AHasher is NOT suitable for this! - use std::collections::hash_map::DefaultHasher; + pub fn with(self, child: impl std::hash::Hash) -> Id { use std::hash::Hasher; - let mut hasher = DefaultHasher::default(); + let mut hasher = epaint::ahash::AHasher::new_with_keys(123, 456); hasher.write_u64(self.0); child.hash(&mut hasher); Id(hasher.finish()) diff --git a/epaint/src/util.rs b/epaint/src/util.rs index 22981841..0f47c1f9 100644 --- a/epaint/src/util.rs +++ b/epaint/src/util.rs @@ -1,7 +1,7 @@ /// Hash the given value with a predictable hasher. #[inline] pub fn hash(value: impl std::hash::Hash) -> u64 { - hash_with(value, std::collections::hash_map::DefaultHasher::default()) + hash_with(value, ahash::AHasher::new_with_keys(123, 456)) } /// Hash the given value with the given hasher.