Use rustc-hash for most of our HashMap and HashSet instances
This commit is contained in:
parent
14ed71e09b
commit
f5bcfec821
19 changed files with 60 additions and 49 deletions
|
|
@ -1,6 +1,7 @@
|
|||
//! Load and draw raster graphics.
|
||||
use crate::{Hasher, Rectangle, Size};
|
||||
use crate::{Rectangle, Size};
|
||||
|
||||
use rustc_hash::FxHasher;
|
||||
use std::hash::{Hash, Hasher as _};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
|
@ -50,7 +51,7 @@ impl Handle {
|
|||
}
|
||||
|
||||
fn from_data(data: Data) -> Handle {
|
||||
let mut hasher = Hasher::default();
|
||||
let mut hasher = FxHasher::default();
|
||||
data.hash(&mut hasher);
|
||||
|
||||
Handle {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ mod background;
|
|||
mod color;
|
||||
mod content_fit;
|
||||
mod element;
|
||||
mod hasher;
|
||||
mod length;
|
||||
mod padding;
|
||||
mod pixels;
|
||||
|
|
@ -64,7 +63,6 @@ pub use element::Element;
|
|||
pub use event::Event;
|
||||
pub use font::Font;
|
||||
pub use gradient::Gradient;
|
||||
pub use hasher::Hasher;
|
||||
pub use layout::Layout;
|
||||
pub use length::Length;
|
||||
pub use overlay::Overlay;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
//! Load and draw vector graphics.
|
||||
use crate::{Color, Hasher, Rectangle, Size};
|
||||
use crate::{Color, Rectangle, Size};
|
||||
|
||||
use rustc_hash::FxHasher;
|
||||
use std::borrow::Cow;
|
||||
use std::hash::{Hash, Hasher as _};
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -30,7 +31,7 @@ impl Handle {
|
|||
}
|
||||
|
||||
fn from_data(data: Data) -> Handle {
|
||||
let mut hasher = Hasher::default();
|
||||
let mut hasher = FxHasher::default();
|
||||
data.hash(&mut hasher);
|
||||
|
||||
Handle {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ iced_core.workspace = true
|
|||
|
||||
futures.workspace = true
|
||||
log.workspace = true
|
||||
rustc-hash.workspace = true
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
async-std.workspace = true
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ impl crate::Executor for Executor {
|
|||
|
||||
pub mod time {
|
||||
//! Listen and react to time.
|
||||
use crate::core::Hasher;
|
||||
use crate::subscription::{self, Subscription};
|
||||
use crate::subscription::{self, Hasher, Subscription};
|
||||
|
||||
/// Returns a [`Subscription`] that produces messages at a set interval.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ impl crate::Executor for Executor {
|
|||
|
||||
pub mod time {
|
||||
//! Listen and react to time.
|
||||
use crate::core::Hasher;
|
||||
use crate::subscription::{self, Subscription};
|
||||
use crate::subscription::{self, Hasher, Subscription};
|
||||
|
||||
/// Returns a [`Subscription`] that produces messages at a set interval.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ impl crate::Executor for Executor {
|
|||
|
||||
pub mod time {
|
||||
//! Listen and react to time.
|
||||
use crate::core::Hasher;
|
||||
use crate::subscription::{self, Subscription};
|
||||
use crate::subscription::{self, Hasher, Subscription};
|
||||
|
||||
/// Returns a [`Subscription`] that produces messages at a set interval.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ mod tracker;
|
|||
pub use tracker::Tracker;
|
||||
|
||||
use crate::core::event::{self, Event};
|
||||
use crate::core::Hasher;
|
||||
use crate::futures::{Future, Stream};
|
||||
use crate::{BoxStream, MaybeSend};
|
||||
|
||||
|
|
@ -18,6 +17,9 @@ use std::hash::Hash;
|
|||
/// It is the input of a [`Subscription`].
|
||||
pub type EventStream = BoxStream<(Event, event::Status)>;
|
||||
|
||||
/// The hasher used for identifying subscriptions.
|
||||
pub type Hasher = rustc_hash::FxHasher;
|
||||
|
||||
/// A request to listen to external events.
|
||||
///
|
||||
/// Besides performing async actions on demand with `Command`, most
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
use crate::core::event::{self, Event};
|
||||
use crate::core::Hasher;
|
||||
use crate::subscription::Recipe;
|
||||
use crate::subscription::{Hasher, Recipe};
|
||||
use crate::{BoxFuture, MaybeSend};
|
||||
|
||||
use futures::channel::mpsc;
|
||||
use futures::sink::{Sink, SinkExt};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::hash::Hasher as _;
|
||||
|
||||
/// A registry of subscription streams.
|
||||
|
|
@ -18,7 +17,7 @@ use std::hash::Hasher as _;
|
|||
/// [`Subscription`]: crate::Subscription
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Tracker {
|
||||
subscriptions: HashMap<u64, Execution>,
|
||||
subscriptions: FxHashMap<u64, Execution>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -31,7 +30,7 @@ impl Tracker {
|
|||
/// Creates a new empty [`Tracker`].
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
subscriptions: HashMap::new(),
|
||||
subscriptions: FxHashMap::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@ pub use crate::core::renderer::{self, Renderer};
|
|||
pub use crate::core::svg;
|
||||
pub use crate::core::text::{self, Text};
|
||||
pub use crate::core::widget::{self, Widget};
|
||||
pub use crate::core::{Hasher, Shell};
|
||||
pub use crate::core::Shell;
|
||||
pub use crate::renderer::graphics;
|
||||
|
||||
pub mod subscription {
|
||||
//! Write your own subscriptions.
|
||||
pub use crate::runtime::futures::subscription::{EventStream, Recipe};
|
||||
pub use crate::runtime::futures::subscription::{
|
||||
EventStream, Hasher, Recipe,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ glyphon.workspace = true
|
|||
guillotiere.workspace = true
|
||||
log.workspace = true
|
||||
once_cell.workspace = true
|
||||
rustc-hash.workspace = true
|
||||
thiserror.workspace = true
|
||||
wgpu.workspace = true
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::graphics;
|
|||
use crate::graphics::image::image_rs;
|
||||
use crate::image::atlas::{self, Atlas};
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
/// Entry in cache corresponding to an image handle
|
||||
#[derive(Debug)]
|
||||
|
|
@ -38,8 +38,8 @@ impl Memory {
|
|||
/// Caches image raster data
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Cache {
|
||||
map: HashMap<u64, Memory>,
|
||||
hits: HashSet<u64>,
|
||||
map: FxHashMap<u64, Memory>,
|
||||
hits: FxHashSet<u64>,
|
||||
}
|
||||
|
||||
impl Cache {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::image::atlas::{self, Atlas};
|
|||
|
||||
use resvg::tiny_skia;
|
||||
use resvg::usvg::{self, TreeTextToPath};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use std::fs;
|
||||
|
||||
/// Entry in cache corresponding to an svg handle
|
||||
|
|
@ -33,10 +33,10 @@ impl Svg {
|
|||
/// Caches svg vector and raster data
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Cache {
|
||||
svgs: HashMap<u64, Svg>,
|
||||
rasterized: HashMap<(u64, u32, u32, ColorFilter), atlas::Entry>,
|
||||
svg_hits: HashSet<u64>,
|
||||
rasterized_hits: HashSet<(u64, u32, u32, ColorFilter)>,
|
||||
svgs: FxHashMap<u64, Svg>,
|
||||
rasterized: FxHashMap<(u64, u32, u32, ColorFilter), atlas::Entry>,
|
||||
svg_hits: FxHashSet<u64>,
|
||||
rasterized_hits: FxHashSet<(u64, u32, u32, ColorFilter)>,
|
||||
}
|
||||
|
||||
type ColorFilter = Option<[u8; 4]>;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
//! Draw primitives using custom pipelines.
|
||||
use crate::core::{self, Rectangle, Size};
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::any::{Any, TypeId};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ impl Renderer for crate::Renderer {
|
|||
/// Stores custom, user-provided pipelines.
|
||||
#[derive(Default, Debug)]
|
||||
pub struct Storage {
|
||||
pipelines: HashMap<TypeId, Box<dyn Any + Send>>,
|
||||
pipelines: FxHashMap<TypeId, Box<dyn Any + Send>>,
|
||||
}
|
||||
|
||||
impl Storage {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
let hash = {
|
||||
let mut hasher = FxHasher::default();
|
||||
self.dependency.hash(&mut hasher);
|
||||
let hash = hasher.finish();
|
||||
|
||||
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();
|
||||
let new_hash = {
|
||||
let mut hasher = FxHasher::default();
|
||||
self.dependency.hash(&mut hasher);
|
||||
let new_hash = hasher.finish();
|
||||
|
||||
hasher.finish()
|
||||
};
|
||||
|
||||
if current.hash != new_hash {
|
||||
current.hash = new_hash;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ iced_graphics.workspace = true
|
|||
iced_runtime.workspace = true
|
||||
|
||||
log.workspace = true
|
||||
rustc-hash.workspace = true
|
||||
thiserror.workspace = true
|
||||
tracing.workspace = true
|
||||
window_clipboard.workspace = true
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use crate::{Clipboard, Error, Proxy, Settings};
|
|||
|
||||
pub use crate::application::{default, Appearance, DefaultStyle};
|
||||
|
||||
use std::collections::HashMap;
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::mem::ManuallyDrop;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
|
|
@ -381,12 +381,12 @@ async fn run_instance<A, E, C>(
|
|||
)]
|
||||
};
|
||||
|
||||
let mut ui_caches = HashMap::new();
|
||||
let mut ui_caches = FxHashMap::default();
|
||||
let mut user_interfaces = ManuallyDrop::new(build_user_interfaces(
|
||||
&application,
|
||||
&mut debug,
|
||||
&mut window_manager,
|
||||
HashMap::from_iter([(
|
||||
FxHashMap::from_iter([(
|
||||
window::Id::MAIN,
|
||||
user_interface::Cache::default(),
|
||||
)]),
|
||||
|
|
@ -759,7 +759,7 @@ async fn run_instance<A, E, C>(
|
|||
|
||||
// TODO mw application update returns which window IDs to update
|
||||
if !messages.is_empty() || uis_stale {
|
||||
let mut cached_interfaces: HashMap<
|
||||
let mut cached_interfaces: FxHashMap<
|
||||
window::Id,
|
||||
user_interface::Cache,
|
||||
> = ManuallyDrop::into_inner(user_interfaces)
|
||||
|
|
@ -849,7 +849,7 @@ fn update<A: Application, C, E: Executor>(
|
|||
debug: &mut Debug,
|
||||
messages: &mut Vec<A::Message>,
|
||||
window_manager: &mut WindowManager<A, C>,
|
||||
ui_caches: &mut HashMap<window::Id, user_interface::Cache>,
|
||||
ui_caches: &mut FxHashMap<window::Id, user_interface::Cache>,
|
||||
) where
|
||||
C: Compositor<Renderer = A::Renderer> + 'static,
|
||||
A::Theme: DefaultStyle,
|
||||
|
|
@ -890,7 +890,7 @@ fn run_command<A, C, E>(
|
|||
proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,
|
||||
debug: &mut Debug,
|
||||
window_manager: &mut WindowManager<A, C>,
|
||||
ui_caches: &mut HashMap<window::Id, user_interface::Cache>,
|
||||
ui_caches: &mut FxHashMap<window::Id, user_interface::Cache>,
|
||||
) where
|
||||
A: Application,
|
||||
E: Executor,
|
||||
|
|
@ -1218,8 +1218,8 @@ pub fn build_user_interfaces<'a, A: Application, C: Compositor>(
|
|||
application: &'a A,
|
||||
debug: &mut Debug,
|
||||
window_manager: &mut WindowManager<A, C>,
|
||||
mut cached_user_interfaces: HashMap<window::Id, user_interface::Cache>,
|
||||
) -> HashMap<window::Id, UserInterface<'a, A::Message, A::Theme, A::Renderer>>
|
||||
mut cached_user_interfaces: FxHashMap<window::Id, user_interface::Cache>,
|
||||
) -> FxHashMap<window::Id, UserInterface<'a, A::Message, A::Theme, A::Renderer>>
|
||||
where
|
||||
C: Compositor<Renderer = A::Renderer>,
|
||||
A::Theme: DefaultStyle,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue