Skip to content

Commit a0476af

Browse files
committed
wayland: Move hash algorithm to foldhash
At the moment, the wayland code uses ahash to perform hashing in its various hash mas. This was done because ahash was seen as the best default in the Rust community at the time. However, most Rust crates (including `hashbrown`) have since moved to using foldhash instead. This move is done for two primary reasons: - This reduces the number of dependencies in the tree for most GUI projects. As other projects use foldhash now, this removes ahash (as well as its five dependencies) from the tree. - In most cases, foldhash is faster than ahash. Signed-off-by: John Nunley <dev@notgull.net>
1 parent 50f9b84 commit a0476af

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ unicode-segmentation = "1.7.1"
6767
windows-sys = "0.59.0"
6868

6969
# Linux dependencies.
70-
ahash = { version = "0.8.7", features = ["no-rng"] }
7170
bytemuck = { version = "1.13.1", default-features = false }
7271
calloop = "0.14.3"
72+
foldhash = { version = "0.2.0", default-features = false, features = ["std"] }
7373
libc = "0.2.64"
7474
memmap2 = "0.9.0"
7575
percent-encoding = "2.0"

winit-wayland/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ tracing.workspace = true
2929
winit-core.workspace = true
3030

3131
# Platform-specific
32-
ahash.workspace = true
3332
calloop.workspace = true
33+
foldhash.workspace = true
3434
libc.workspace = true
3535
memmap2.workspace = true
3636
rustix = { workspace = true, features = ["std", "system", "thread", "process", "event", "pipe"] }

winit-wayland/src/seat/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::sync::Arc;
44

5-
use ahash::AHashMap;
5+
use foldhash::HashMap;
66
use sctk::reexports::client::backend::ObjectId;
77
use sctk::reexports::client::protocol::wl_seat::WlSeat;
88
use sctk::reexports::client::protocol::wl_touch::WlTouch;
@@ -43,7 +43,7 @@ pub struct WinitSeatState {
4343
touch: Option<WlTouch>,
4444

4545
/// The mapping from touched points to the surfaces they're present.
46-
touch_map: AHashMap<i32, TouchPoint>,
46+
touch_map: HashMap<i32, TouchPoint>,
4747

4848
/// Id of the first touch event.
4949
first_touch_id: Option<i32>,

winit-wayland/src/state.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::cell::RefCell;
22
use std::sync::atomic::Ordering;
33
use std::sync::{Arc, Mutex};
44

5-
use ahash::AHashMap;
5+
use foldhash::HashMap;
66
use sctk::compositor::{CompositorHandler, CompositorState};
77
use sctk::output::{OutputHandler, OutputState};
88
use sctk::reexports::calloop::LoopHandle;
@@ -62,10 +62,10 @@ pub struct WinitState {
6262
pub xdg_shell: XdgShell,
6363

6464
/// The currently present windows.
65-
pub windows: RefCell<AHashMap<WindowId, Arc<Mutex<WindowState>>>>,
65+
pub windows: RefCell<HashMap<WindowId, Arc<Mutex<WindowState>>>>,
6666

6767
/// The requests from the `Window` to EventLoop, such as close operations and redraw requests.
68-
pub window_requests: RefCell<AHashMap<WindowId, Arc<WindowRequests>>>,
68+
pub window_requests: RefCell<HashMap<WindowId, Arc<WindowRequests>>>,
6969

7070
/// The events that were generated directly from the window.
7171
pub window_events_sink: Arc<Mutex<EventSink>>,
@@ -74,10 +74,10 @@ pub struct WinitState {
7474
pub window_compositor_updates: Vec<WindowCompositorUpdate>,
7575

7676
/// Currently handled seats.
77-
pub seats: AHashMap<ObjectId, WinitSeatState>,
77+
pub seats: HashMap<ObjectId, WinitSeatState>,
7878

7979
/// Currently present cursor surfaces.
80-
pub pointer_surfaces: AHashMap<ObjectId, Arc<ThemedPointer<WinitPointerData>>>,
80+
pub pointer_surfaces: HashMap<ObjectId, Arc<ThemedPointer<WinitPointerData>>>,
8181

8282
/// The state of the text input on the client.
8383
pub text_input_state: Option<TextInputState>,
@@ -156,7 +156,7 @@ impl WinitState {
156156

157157
let seat_state = SeatState::new(globals, queue_handle);
158158

159-
let mut seats = AHashMap::default();
159+
let mut seats = HashMap::default();
160160
for seat in seat_state.seats() {
161161
seats.insert(seat.id(), WinitSeatState::new());
162162
}

winit-wayland/src/window/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::num::NonZeroU32;
44
use std::sync::{Arc, Mutex, Weak};
55
use std::time::Duration;
66

7-
use ahash::HashSet;
7+
use foldhash::HashSet;
88
use dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Size};
99
use sctk::compositor::{CompositorState, Region, SurfaceData, SurfaceDataExt};
1010
use sctk::globals::GlobalData;

winit/src/changelog/unreleased.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ changelog entry.
4848

4949
- On X11, fix `set_hittest` not working on some window managers.
5050
- On Redox, handle `EINTR` when reading from `event_socket` instead of panicking.
51+
- On Wayland, switch from using the `ahash` hashing algorithm to `foldhash`.

0 commit comments

Comments
 (0)