diff options
author | 2024-04-01 11:59:46 +0200 | |
---|---|---|
committer | 2024-04-01 12:00:15 +0200 | |
commit | f5bcfec8211c04c4b05f63d01d52d3e5d2cc123e (patch) | |
tree | 4a9f0699548cea15b43743dcf00d5628890610ab /widget | |
parent | 14ed71e09b648693dfca9eb29f14147c5c03a6bc (diff) | |
download | iced-f5bcfec8211c04c4b05f63d01d52d3e5d2cc123e.tar.gz iced-f5bcfec8211c04c4b05f63d01d52d3e5d2cc123e.tar.bz2 iced-f5bcfec8211c04c4b05f63d01d52d3e5d2cc123e.zip |
Use `rustc-hash` for most of our `HashMap` and `HashSet` instances
Diffstat (limited to 'widget')
-rw-r--r-- | widget/Cargo.toml | 1 | ||||
-rw-r--r-- | widget/src/lazy.rs | 21 | ||||
-rw-r--r-- | widget/src/pane_grid/state.rs | 8 |
3 files changed, 19 insertions, 11 deletions
diff --git a/widget/Cargo.toml b/widget/Cargo.toml index a45f47ef..84525935 100644 --- a/widget/Cargo.toml +++ b/widget/Cargo.toml @@ -28,6 +28,7 @@ iced_renderer.workspace = true iced_runtime.workspace = true num-traits.workspace = true +rustc-hash.workspace = true thiserror.workspace = true unicode-segmentation.workspace = true diff --git a/widget/src/lazy.rs b/widget/src/lazy.rs index eb663ea5..04783dbe 100644 --- a/widget/src/lazy.rs +++ b/widget/src/lazy.rs @@ -18,11 +18,12 @@ use crate::core::widget::tree::{self, Tree}; use crate::core::widget::{self, Widget}; use crate::core::Element; use crate::core::{ - self, Clipboard, Hasher, Length, Point, Rectangle, Shell, Size, Vector, + self, Clipboard, Length, Point, Rectangle, Shell, Size, Vector, }; use crate::runtime::overlay::Nested; use ouroboros::self_referencing; +use rustc_hash::FxHasher; use std::cell::RefCell; use std::hash::{Hash, Hasher as H}; use std::rc::Rc; @@ -106,9 +107,12 @@ where } fn state(&self) -> tree::State { - let mut hasher = Hasher::default(); - self.dependency.hash(&mut hasher); - let hash = hasher.finish(); + let hash = { + let mut hasher = FxHasher::default(); + self.dependency.hash(&mut hasher); + + hasher.finish() + }; let element = Rc::new(RefCell::new(Some((self.view)(&self.dependency).into()))); @@ -127,9 +131,12 @@ where .state .downcast_mut::<Internal<Message, Theme, Renderer>>(); - let mut hasher = Hasher::default(); - self.dependency.hash(&mut hasher); - let new_hash = hasher.finish(); + let new_hash = { + let mut hasher = FxHasher::default(); + self.dependency.hash(&mut hasher); + + hasher.finish() + }; if current.hash != new_hash { current.hash = new_hash; diff --git a/widget/src/pane_grid/state.rs b/widget/src/pane_grid/state.rs index 481cd770..c20c3b9c 100644 --- a/widget/src/pane_grid/state.rs +++ b/widget/src/pane_grid/state.rs @@ -6,7 +6,7 @@ use crate::pane_grid::{ Axis, Configuration, Direction, Edge, Node, Pane, Region, Split, Target, }; -use std::collections::HashMap; +use rustc_hash::FxHashMap; /// The state of a [`PaneGrid`]. /// @@ -25,7 +25,7 @@ pub struct State<T> { /// The panes of the [`PaneGrid`]. /// /// [`PaneGrid`]: super::PaneGrid - pub panes: HashMap<Pane, T>, + pub panes: FxHashMap<Pane, T>, /// The internal state of the [`PaneGrid`]. /// @@ -52,7 +52,7 @@ impl<T> State<T> { /// Creates a new [`State`] with the given [`Configuration`]. pub fn with_configuration(config: impl Into<Configuration<T>>) -> Self { - let mut panes = HashMap::new(); + let mut panes = FxHashMap::default(); let internal = Internal::from_configuration(&mut panes, config.into(), 0); @@ -353,7 +353,7 @@ impl Internal { /// /// [`PaneGrid`]: super::PaneGrid pub fn from_configuration<T>( - panes: &mut HashMap<Pane, T>, + panes: &mut FxHashMap<Pane, T>, content: Configuration<T>, next_id: usize, ) -> Self { |