diff --git a/src/backends/metal.rs b/src/backends/metal.rs index 8cf68ae9..4b5e8c03 100644 --- a/src/backends/metal.rs +++ b/src/backends/metal.rs @@ -35,6 +35,7 @@ use { clonecell::{CloneCell, UnsafeCellCloneSafe}, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, + hash_map_ext::HashMapExt, numcell::NumCell, oserror::OsError, smallmap::SmallMap, @@ -184,7 +185,7 @@ impl Backend for MetalBackend { dev.cb.take(); } } - for (_, dev) in self.device_holder.drm_devices.lock().drain() { + for dev in self.device_holder.drm_devices.lock().drain_values() { dev.futures.clear(); for crtc in dev.dev.crtcs.values() { crtc.connector.take(); @@ -196,13 +197,13 @@ impl Backend for MetalBackend { lease.crtcs.clear(); lease.planes.clear(); }; - for (_, mut lease) in dev.dev.leases.lock().drain() { + for mut lease in dev.dev.leases.lock().drain_values() { clear_lease(&mut lease); } - for (_, mut lease) in dev.dev.leases_to_break.lock().drain() { + for mut lease in dev.dev.leases_to_break.lock().drain_values() { clear_lease(&mut lease); } - for (_, connector) in dev.connectors.lock().drain() { + for connector in dev.connectors.lock().drain_values() { { let d = &mut *connector.display.borrow_mut(); d.crtcs.clear(); diff --git a/src/cursor_user.rs b/src/cursor_user.rs index f16abf3c..0c66c675 100644 --- a/src/cursor_user.rs +++ b/src/cursor_user.rs @@ -6,8 +6,8 @@ use { state::State, tree::OutputNode, utils::{ - clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, rc_eq::rc_eq, - transform_ext::TransformExt, + clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, + hash_map_ext::HashMapExt, rc_eq::rc_eq, transform_ext::TransformExt, }, }, std::{cell::Cell, ops::Deref, rc::Rc}, @@ -99,7 +99,7 @@ impl CursorUserGroup { .set(self.state.dummy_output.get().unwrap()); self.state.remove_cursor_size(self.size.get()); self.state.cursor_user_groups.remove(&self.id); - for (_, user) in self.users.lock().drain() { + for user in self.users.lock().drain_values() { user.detach(); } } diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index be5cab5a..8af8f3b6 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -33,7 +33,7 @@ use { object::Version, state::DeviceHandlerData, tree::{Direction, Node, ToplevelNode}, - utils::{bitflags::BitflagsExt, smallmap::SmallMap}, + utils::{bitflags::BitflagsExt, hash_map_ext::HashMapExt, smallmap::SmallMap}, wire::WlDataOfferId, xkbcommon::{KeyboardState, XkbState, XKB_KEY_DOWN, XKB_KEY_UP}, }, @@ -237,7 +237,7 @@ impl WlSeatGlobal { | InputEvent::TabletPadStrip { time_usec, .. } => { self.last_input_usec.set(time_usec); if self.idle_notifications.is_not_empty() { - for (_, notification) in self.idle_notifications.lock().drain() { + for notification in self.idle_notifications.lock().drain_values() { notification.resume.trigger(); } } diff --git a/src/ifs/wl_seat/tablet.rs b/src/ifs/wl_seat/tablet.rs index bd8517d6..9bf7fc44 100644 --- a/src/ifs/wl_seat/tablet.rs +++ b/src/ifs/wl_seat/tablet.rs @@ -19,7 +19,10 @@ use { object::Version, time::now_usec, tree::{FoundNode, Node}, - utils::{bindings::PerClientBindings, clonecell::CloneCell, copyhashmap::CopyHashMap}, + utils::{ + bindings::PerClientBindings, clonecell::CloneCell, copyhashmap::CopyHashMap, + hash_map_ext::HashMapExt, + }, }, std::{ cell::{Cell, RefCell}, @@ -293,18 +296,18 @@ impl WlSeatGlobal { pub fn tablet_clear(&self) { self.tablet.seats.clear(); - for (_, tablet) in self.tablet.tablets.lock().drain() { + for tablet in self.tablet.tablets.lock().drain_values() { tablet.pads.clear(); tablet.bindings.clear(); tablet.tools.clear(); } - for (_, tool) in self.tablet.tools.lock().drain() { + for tool in self.tablet.tools.lock().drain_values() { tool.cursor.detach(); tool.opt.tool.take(); tool.tool_owner.destroy(&tool); tool.bindings.clear(); } - for (_, pad) in self.tablet.pads.lock().drain() { + for pad in self.tablet.pads.lock().drain_values() { pad.pad_owner.destroy(&pad); pad.tablet.take(); pad.bindings.clear(); @@ -324,14 +327,14 @@ impl WlSeatGlobal { let Some(tablet) = self.tablet.tablets.remove(&id) else { return; }; - for (_, tool) in tablet.tools.lock().drain() { + for tool in tablet.tools.lock().drain_values() { self.tablet_handle_remove_tool(now_usec(), tool.id); } - for (_, pad) in tablet.pads.lock().drain() { + for pad in tablet.pads.lock().drain_values() { pad.pad_owner.destroy(&pad); pad.tablet.take(); } - for (_, binding) in tablet.bindings.lock().drain() { + for binding in tablet.bindings.lock().drain_values() { binding.send_removed(); } } diff --git a/src/ifs/wl_seat/tablet/pad.rs b/src/ifs/wl_seat/tablet/pad.rs index 7eddb329..c39c5109 100644 --- a/src/ifs/wl_seat/tablet/pad.rs +++ b/src/ifs/wl_seat/tablet/pad.rs @@ -14,7 +14,7 @@ use { wl_surface::WlSurface, }, time::{now_usec, usec_to_msec}, - utils::clonecell::CloneCell, + utils::{clonecell::CloneCell, hash_map_ext::HashMapExt}, }, std::{cell::Cell, rc::Rc}, }; @@ -76,7 +76,7 @@ impl WlSeatGlobal { if let Some(tablet) = pad.tablet.take() { tablet.pads.remove(&pad.id); } - for (_, binding) in pad.bindings.lock().drain() { + for binding in pad.bindings.lock().drain_values() { binding.send_removed(); } } diff --git a/src/ifs/wl_seat/tablet/tool.rs b/src/ifs/wl_seat/tablet/tool.rs index 9f11ea5f..61fa6306 100644 --- a/src/ifs/wl_seat/tablet/tool.rs +++ b/src/ifs/wl_seat/tablet/tool.rs @@ -15,7 +15,7 @@ use { }, rect::Rect, time::usec_to_msec, - utils::clonecell::CloneCell, + utils::{clonecell::CloneCell, hash_map_ext::HashMapExt}, }, std::{cell::Cell, rc::Rc}, }; @@ -31,7 +31,7 @@ impl WlSeatGlobal { tool.opt.tool.take(); tool.cursor.detach(); tool.tool_owner.destroy(&tool); - for (_, binding) in tool.bindings.lock().drain() { + for binding in tool.bindings.lock().drain_values() { binding.send_removed(); } tool.tablet.tools.remove(&id); diff --git a/src/ifs/wl_surface/commit_timeline.rs b/src/ifs/wl_surface/commit_timeline.rs index df6deb94..a150b6fa 100644 --- a/src/ifs/wl_surface/commit_timeline.rs +++ b/src/ifs/wl_surface/commit_timeline.rs @@ -4,6 +4,7 @@ use { utils::{ clonecell::CloneCell, copyhashmap::CopyHashMap, + hash_map_ext::HashMapExt, linkedlist::{LinkedList, LinkedNode, NodeRef}, numcell::NumCell, }, @@ -102,7 +103,7 @@ impl CommitTimelines { } pub fn clear(&self) { - for (_, list) in self.gc.lock().drain() { + for list in self.gc.lock().drain_values() { break_loops(&list); } } diff --git a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs index ae1a377d..5c93bd6e 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs @@ -29,7 +29,7 @@ use { OutputNode, ToplevelData, ToplevelNode, ToplevelNodeBase, ToplevelNodeId, WorkspaceNode, }, - utils::clonecell::CloneCell, + utils::{clonecell::CloneCell, hash_map_ext::HashMapExt}, wire::{xdg_toplevel::*, XdgToplevelId}, }, ahash::{AHashMap, AHashSet}, @@ -218,7 +218,7 @@ impl XdgToplevelRequestHandler for XdgToplevel { Some(p) => Some(p.children.borrow_mut()), _ => None, }; - for (_, child) in children.drain() { + for child in children.drain_values() { child.parent.set(parent.clone()); if let Some(parent_children) = &mut parent_children { parent_children.insert(child.id, child); @@ -418,7 +418,7 @@ impl XdgToplevel { { let new_parent = self.parent.get(); let mut children = self.children.borrow_mut(); - for (_, child) in children.drain() { + for child in children.drain_values() { child.parent.set(new_parent.clone()); } } diff --git a/src/ifs/zwp_linux_buffer_params_v1.rs b/src/ifs/zwp_linux_buffer_params_v1.rs index db1914a6..025cbc1b 100644 --- a/src/ifs/zwp_linux_buffer_params_v1.rs +++ b/src/ifs/zwp_linux_buffer_params_v1.rs @@ -5,7 +5,7 @@ use { ifs::{wl_buffer::WlBuffer, zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1}, leaks::Tracker, object::Object, - utils::errorfmt::ErrorFmt, + utils::{errorfmt::ErrorFmt, hash_map_ext::HashMapExt}, video::dmabuf::{DmaBuf, DmaBufPlane, PlaneVec, MAX_PLANES}, wire::{zwp_linux_buffer_params_v1::*, WlBufferId, ZwpLinuxBufferParamsV1Id}, }, @@ -90,7 +90,7 @@ impl ZwpLinuxBufferParamsV1 { modifier, planes: PlaneVec::new(), }; - let mut planes: Vec<_> = self.planes.borrow_mut().drain().map(|v| v.1).collect(); + let mut planes: Vec<_> = self.planes.borrow_mut().drain_values().collect(); planes.sort_by_key(|a| a.plane_idx); for (i, p) in planes.into_iter().enumerate() { if p.plane_idx as usize != i { diff --git a/src/it/test_transport.rs b/src/it/test_transport.rs index d0bb3063..da8484f0 100644 --- a/src/it/test_transport.rs +++ b/src/it/test_transport.rs @@ -15,6 +15,7 @@ use { bitfield::Bitfield, buffd::{BufFdIn, BufFdOut, MsgFormatter, MsgParser, OutBuffer, OutBufferSwapchain}, copyhashmap::CopyHashMap, + hash_map_ext::HashMapExt, stack::Stack, vec_ext::VecExt, }, @@ -105,7 +106,7 @@ impl TestTransport { pub fn kill(&self) { self.outgoing.take(); self.incoming.take(); - for (_, object) in self.objects.lock().drain() { + for object in self.objects.lock().drain_values() { object.on_remove(self); } } diff --git a/src/leaks.rs b/src/leaks.rs index 343e023c..6a6f0c57 100644 --- a/src/leaks.rs +++ b/src/leaks.rs @@ -43,6 +43,7 @@ mod leaks { crate::{ client::ClientId, utils::{ + hash_map_ext::HashMapExt, ptr_ext::{MutPtrExt, PtrExt}, windows::WindowsExt, }, @@ -157,7 +158,7 @@ mod leaks { if map.is_empty() { log::info!("No leaks"); } - for (_, mut objs) in map.drain() { + for mut objs in map.drain_values() { if objs.len() == 0 { continue; } diff --git a/src/pipewire/pw_con.rs b/src/pipewire/pw_con.rs index 6fe93ed5..51cec2b8 100644 --- a/src/pipewire/pw_con.rs +++ b/src/pipewire/pw_con.rs @@ -23,6 +23,7 @@ use { clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, + hash_map_ext::HashMapExt, numcell::NumCell, oserror::OsError, xrd::xrd, @@ -122,7 +123,7 @@ impl PwCon { } pub fn kill(&self) { - for (_, obj) in self.objects.lock().drain() { + for obj in self.objects.lock().drain_values() { obj.break_loops(); } self.io.shutdown(); diff --git a/src/portal/ptl_display.rs b/src/portal/ptl_display.rs index 84539061..9d078e89 100644 --- a/src/portal/ptl_display.rs +++ b/src/portal/ptl_display.rs @@ -8,7 +8,7 @@ use { }, utils::{ bitflags::BitflagsExt, clonecell::CloneCell, copyhashmap::CopyHashMap, - errorfmt::ErrorFmt, oserror::OsError, + errorfmt::ErrorFmt, hash_map_ext::HashMapExt, oserror::OsError, }, video::drm::Drm, wire::{ @@ -191,7 +191,7 @@ impl UsrJayRenderCtxOwner for PortalDisplay { impl UsrConOwner for PortalDisplay { fn killed(&self) { log::info!("Removing display {}", self.id); - for (_, sc) in self.screencasts.lock().drain() { + for sc in self.screencasts.lock().drain_values() { sc.kill(); } self.windows.clear(); diff --git a/src/portal/ptl_screencast.rs b/src/portal/ptl_screencast.rs index 00c42514..fafc706b 100644 --- a/src/portal/ptl_screencast.rs +++ b/src/portal/ptl_screencast.rs @@ -21,6 +21,7 @@ use { utils::{ clonecell::{CloneCell, UnsafeCellCloneSafe}, copyhashmap::CopyHashMap, + hash_map_ext::HashMapExt, }, video::dmabuf::{DmaBuf, PlaneVec}, wire::jay_screencast::Ready, @@ -267,7 +268,7 @@ impl ScreencastSession { ScreencastPhase::Terminated => {} ScreencastPhase::Selecting(s) => { s.core.reply.err("Session has been terminated"); - for (_, gui) in s.guis.lock().drain() { + for gui in s.guis.lock().drain_values() { gui.kill(false); } } diff --git a/src/portal/ptl_screencast/screencast_gui.rs b/src/portal/ptl_screencast/screencast_gui.rs index 016c9b66..9ae787a6 100644 --- a/src/portal/ptl_screencast/screencast_gui.rs +++ b/src/portal/ptl_screencast/screencast_gui.rs @@ -13,7 +13,7 @@ use { }, }, theme::Color, - utils::copyhashmap::CopyHashMap, + utils::{copyhashmap::CopyHashMap, hash_map_ext::HashMapExt}, wl_usr::usr_ifs::{ usr_jay_select_toplevel::UsrJaySelectToplevelOwner, usr_jay_select_workspace::UsrJaySelectWorkspaceOwner, usr_jay_toplevel::UsrJayToplevel, @@ -53,7 +53,7 @@ enum ButtonRole { impl SelectionGui { pub fn kill(&self, upwards: bool) { - for (_, surface) in self.surfaces.lock().drain() { + for surface in self.surfaces.lock().drain_values() { surface.overlay.data.kill(false); } if let ScreencastPhase::Selecting(s) = self.screencast_session.phase.get() { @@ -159,7 +159,7 @@ impl ButtonOwner for StaticButton { ScreencastPhase::Selecting(selecting) => selecting, _ => return, }; - for (_, gui) in selecting.guis.lock().drain() { + for gui in selecting.guis.lock().drain_values() { gui.kill(false); } let dpy = &self.surface.output.dpy; diff --git a/src/portal/ptr_gui.rs b/src/portal/ptr_gui.rs index 3020d219..0bd6e509 100644 --- a/src/portal/ptr_gui.rs +++ b/src/portal/ptr_gui.rs @@ -13,7 +13,7 @@ use { theme::Color, utils::{ asyncevent::AsyncEvent, clonecell::CloneCell, copyhashmap::CopyHashMap, - errorfmt::ErrorFmt, rc_eq::rc_eq, + errorfmt::ErrorFmt, hash_map_ext::HashMapExt, rc_eq::rc_eq, }, video::gbm::GBM_BO_USE_RENDERING, wire::{ @@ -671,7 +671,7 @@ impl WindowData { owner.kill(upwards); } self.render_task.take(); - for (_, pb) in self.pending_bufs.lock().drain() { + for pb in self.pending_bufs.lock().drain_values() { pb.params.con.remove_obj(pb.params.deref()); } for buf in self.bufs.borrow_mut().drain(..) { @@ -689,7 +689,7 @@ impl WindowData { pub fn allocate_buffers(self: &Rc) { { - for (_, buf) in self.pending_bufs.lock().drain() { + for buf in self.pending_bufs.lock().drain_values() { buf.params.con.remove_obj(buf.params.deref()); } } diff --git a/src/security_context_acceptor.rs b/src/security_context_acceptor.rs index 69f102af..7d4ae7d0 100644 --- a/src/security_context_acceptor.rs +++ b/src/security_context_acceptor.rs @@ -3,7 +3,7 @@ use { async_engine::SpawnedFuture, client::ClientCaps, state::State, - utils::{copyhashmap::CopyHashMap, errorfmt::ErrorFmt}, + utils::{copyhashmap::CopyHashMap, errorfmt::ErrorFmt, hash_map_ext::HashMapExt}, }, std::{ cell::Cell, @@ -36,7 +36,7 @@ struct Acceptor { impl SecurityContextAcceptors { pub fn clear(&self) { - for (_, acceptor) in self.acceptors.lock().drain() { + for acceptor in self.acceptors.lock().drain_values() { acceptor.kill(); } } diff --git a/src/state.rs b/src/state.rs index 73abb7df..8246aeb1 100644 --- a/src/state.rs +++ b/src/state.rs @@ -68,8 +68,8 @@ use { utils::{ activation_token::ActivationToken, asyncevent::AsyncEvent, bindings::Bindings, clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, fdcloser::FdCloser, - linkedlist::LinkedList, numcell::NumCell, queue::AsyncQueue, refcounted::RefCounted, - run_toplevel::RunToplevel, + hash_map_ext::HashMapExt, linkedlist::LinkedList, numcell::NumCell, queue::AsyncQueue, + refcounted::RefCounted, run_toplevel::RunToplevel, }, video::{ dmabuf::DmaBufIds, @@ -743,11 +743,11 @@ impl State { self.xwayland.queue.clear(); self.idle.inhibitors.clear(); self.idle.change.clear(); - for (_, drm_dev) in self.drm_devs.lock().drain() { + for drm_dev in self.drm_devs.lock().drain_values() { drm_dev.handler.take(); drm_dev.connectors.clear(); } - for (_, connector) in self.connectors.lock().drain() { + for connector in self.connectors.lock().drain_values() { connector.handler.take(); connector.async_event.clear(); } @@ -769,7 +769,7 @@ impl State { self.toplevel_lists.clear(); self.security_context_acceptors.clear(); self.slow_clients.clear(); - for (_, h) in self.input_device_handlers.borrow_mut().drain() { + for h in self.input_device_handlers.borrow_mut().drain_values() { h.async_event.clear(); } self.backend_events.clear(); diff --git a/src/tasks/connector.rs b/src/tasks/connector.rs index 2824010c..901b439a 100644 --- a/src/tasks/connector.rs +++ b/src/tasks/connector.rs @@ -5,7 +5,7 @@ use { ifs::wl_output::{OutputId, PersistentOutputState, WlOutputGlobal}, state::{ConnectorData, OutputData, State}, tree::{move_ws_to_output, OutputNode, OutputRenderData, WsMoveConfig}, - utils::{asyncevent::AsyncEvent, clonecell::CloneCell}, + utils::{asyncevent::AsyncEvent, clonecell::CloneCell, hash_map_ext::HashMapExt}, }, std::{ cell::{Cell, RefCell}, @@ -244,14 +244,14 @@ impl ConnectorHandler { config.connector_disconnected(self.id); } global.clear(); - for (_, jo) in on.jay_outputs.lock().drain() { + for jo in on.jay_outputs.lock().drain_values() { jo.send_destroyed(); } let screencasts: Vec<_> = on.screencasts.lock().values().cloned().collect(); for sc in screencasts { sc.do_destroy(); } - for (_, sc) in on.screencopies.lock().drain() { + for sc in on.screencopies.lock().drain_values() { sc.send_failed(); } global.destroyed.set(true); @@ -310,7 +310,7 @@ impl ConnectorHandler { } }; let withdraw = || { - for (_, con) in output_data.lease_connectors.lock().drain() { + for con in output_data.lease_connectors.lock().drain_values() { con.send_withdrawn(); if !con.device.destroyed.get() { con.device.send_done(); diff --git a/src/tree/container.rs b/src/tree/container.rs index 4ad79051..052ecdb0 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -23,6 +23,7 @@ use { clonecell::CloneCell, double_click_state::DoubleClickState, errorfmt::ErrorFmt, + hash_map_ext::HashMapExt, linkedlist::{LinkedList, LinkedNode, NodeRef}, numcell::NumCell, rc_eq::rc_eq, @@ -1613,7 +1614,7 @@ impl ToplevelNodeBase for ContainerNode { fn tl_destroy_impl(&self) { mem::take(self.cursors.borrow_mut().deref_mut()); let mut cn = self.child_nodes.borrow_mut(); - for (_, n) in cn.drain() { + for n in cn.drain_values() { n.node.tl_destroy(); } } diff --git a/src/tree/output.rs b/src/tree/output.rs index 8c009de7..2582d64a 100644 --- a/src/tree/output.rs +++ b/src/tree/output.rs @@ -36,7 +36,8 @@ use { }, utils::{ clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, - linkedlist::LinkedList, scroller::Scroller, transform_ext::TransformExt, + hash_map_ext::HashMapExt, linkedlist::LinkedList, scroller::Scroller, + transform_ext::TransformExt, }, wire::{JayOutputId, JayScreencastId, ZwlrScreencopyFrameV1Id}, }, @@ -140,7 +141,7 @@ impl OutputNode { return; } let now = Time::now().unwrap(); - for (_, capture) in self.screencopies.lock().drain() { + for capture in self.screencopies.lock().drain_values() { let wl_buffer = match capture.buffer.take() { Some(b) => b, _ => { diff --git a/src/tree/toplevel.rs b/src/tree/toplevel.rs index 7aefabe3..ee6ecdfc 100644 --- a/src/tree/toplevel.rs +++ b/src/tree/toplevel.rs @@ -15,6 +15,7 @@ use { utils::{ clonecell::CloneCell, copyhashmap::CopyHashMap, + hash_map_ext::HashMapExt, numcell::NumCell, smallmap::SmallMap, threshold_counter::ThresholdCounter, @@ -289,16 +290,16 @@ impl ToplevelData { } pub fn destroy_node(&self, node: &dyn Node) { - for (_, jay_tl) in self.jay_toplevels.lock().drain() { + for jay_tl in self.jay_toplevels.lock().drain_values() { jay_tl.destroy(); } - for (_, screencast) in self.jay_screencasts.lock().drain() { + for screencast in self.jay_screencasts.lock().drain_values() { screencast.do_destroy(); } self.identifier.set(toplevel_identifier()); { let mut handles = self.handles.lock(); - for (_, handle) in handles.drain() { + for handle in handles.drain_values() { handle.send_closed(); } } diff --git a/src/utils.rs b/src/utils.rs index 8531378c..850931c7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -16,6 +16,7 @@ pub mod double_click_state; pub mod errorfmt; pub mod fdcloser; pub mod gfx_api_ext; +pub mod hash_map_ext; pub mod hex; pub mod line_logger; pub mod linkedlist; diff --git a/src/utils/hash_map_ext.rs b/src/utils/hash_map_ext.rs new file mode 100644 index 00000000..53ce1030 --- /dev/null +++ b/src/utils/hash_map_ext.rs @@ -0,0 +1,15 @@ +use std::collections::HashMap; + +pub trait HashMapExt { + type V; + + fn drain_values(&mut self) -> impl Iterator; +} + +impl HashMapExt for HashMap { + type V = V; + + fn drain_values(&mut self) -> impl Iterator { + self.drain().map(|(_, v)| v) + } +} diff --git a/src/video/drm/sync_obj.rs b/src/video/drm/sync_obj.rs index 3eb8e355..d1d74f6a 100644 --- a/src/video/drm/sync_obj.rs +++ b/src/video/drm/sync_obj.rs @@ -5,6 +5,7 @@ use { clonecell::{CloneCell, UnsafeCellCloneSafe}, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, + hash_map_ext::HashMapExt, linkedlist::{LinkedList, LinkedNode}, oserror::OsError, }, @@ -230,7 +231,7 @@ impl Drop for SyncObjCtx { fn drop(&mut self) { self.inner.links.clear(); let mut map = self.inner.handles.lock(); - for (_, handle) in map.drain() { + for handle in map.drain_values() { destroy(&self.inner.drm, handle); } } diff --git a/src/video/drm/wait_for_sync_obj.rs b/src/video/drm/wait_for_sync_obj.rs index a01788f2..f22a1095 100644 --- a/src/video/drm/wait_for_sync_obj.rs +++ b/src/video/drm/wait_for_sync_obj.rs @@ -4,7 +4,7 @@ use { io_uring::IoUring, utils::{ asyncevent::AsyncEvent, buf::Buf, clonecell::CloneCell, copyhashmap::CopyHashMap, - numcell::NumCell, oserror::OsError, stack::Stack, + hash_map_ext::HashMapExt, numcell::NumCell, oserror::OsError, stack::Stack, }, video::drm::{ sync_obj::{SyncObj, SyncObjCtx, SyncObjPoint}, @@ -89,7 +89,7 @@ impl WaitForSyncObj { pub fn set_ctx(&self, ctx: Option>) { self.inner.ctx.set(ctx); - let busy_waiters: Vec<_> = self.inner.busy.lock().drain().map(|(_, w)| w).collect(); + let busy_waiters: Vec<_> = self.inner.busy.lock().drain_values().collect(); for waiter in busy_waiters { let res = self.submit_job( waiter.job.id, diff --git a/src/wheel.rs b/src/wheel.rs index 2ffe6786..5c7dedb5 100644 --- a/src/wheel.rs +++ b/src/wheel.rs @@ -4,8 +4,8 @@ use { io_uring::{IoUring, IoUringError}, time::{Time, TimeError}, utils::{ - buf::TypedBuf, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, numcell::NumCell, - oserror::OsError, stack::Stack, + buf::TypedBuf, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, hash_map_ext::HashMapExt, + numcell::NumCell, oserror::OsError, stack::Stack, }, }, std::{ @@ -204,7 +204,7 @@ impl WheelData { self.destroyed.set(true); self.dispatcher.set(None); self.cached_futures.take(); - for (_, dispatcher) in self.dispatchers.lock().drain() { + for dispatcher in self.dispatchers.lock().drain_values() { dispatcher.complete(Err(WheelError::Destroyed)); } } diff --git a/src/wl_usr.rs b/src/wl_usr.rs index 1b2fc47a..4feffa64 100644 --- a/src/wl_usr.rs +++ b/src/wl_usr.rs @@ -17,6 +17,7 @@ use { clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, + hash_map_ext::HashMapExt, oserror::OsError, vec_ext::VecExt, }, @@ -159,7 +160,7 @@ impl UsrCon { pub fn kill(&self) { self.dead.set(true); - for (_, obj) in self.objects.lock().drain() { + for obj in self.objects.lock().drain_values() { if let Some(obj) = obj { obj.break_loops(); } diff --git a/src/xwayland/xwm.rs b/src/xwayland/xwm.rs index 82fdef48..f05fcb54 100644 --- a/src/xwayland/xwm.rs +++ b/src/xwayland/xwm.rs @@ -27,8 +27,8 @@ use { tree::{Node, ToplevelNode}, utils::{ bitflags::BitflagsExt, buf::Buf, cell_ext::CellExt, clonecell::CloneCell, - copyhashmap::CopyHashMap, errorfmt::ErrorFmt, linkedlist::LinkedList, numcell::NumCell, - oserror::OsError, rc_eq::rc_eq, + copyhashmap::CopyHashMap, errorfmt::ErrorFmt, hash_map_ext::HashMapExt, + linkedlist::LinkedList, numcell::NumCell, oserror::OsError, rc_eq::rc_eq, }, wire::WlSurfaceId, wire_xcon::{ @@ -171,7 +171,7 @@ struct SelectionData { impl SelectionData { fn destroy(&self) { - for (_, offer) in self.offers.lock().drain() { + for offer in self.offers.lock().drain_values() { destroy_data_offer::(&offer.offer); } self.active_offer.take(); @@ -179,7 +179,7 @@ impl SelectionData { } fn destroy_sources(&self) { - for (_, source) in self.sources.lock().drain() { + for source in self.sources.lock().drain_values() { destroy_data_source::(&source); } } @@ -207,7 +207,7 @@ impl Drop for XwmShared { fn drop(&mut self) { self.data.destroy(); self.primary_selection.destroy(); - for (_, device) in self.devices.lock().drain() { + for device in self.devices.lock().drain_values() { destroy_data_device::(&device); destroy_data_device::(&device); device.seat.unset_x_data_device(device.id); @@ -260,7 +260,7 @@ enum Initiator { impl Drop for Wm { fn drop(&mut self) { - for (_, window) in self.windows.drain() { + for window in self.windows.drain_values() { if let Some(window) = window.window.take() { window.break_loops(); } @@ -1985,7 +1985,7 @@ impl Wm { } { let mut children = data.children.lock(); - for (_, child) in children.drain() { + for child in children.drain_values() { child.parent.set(None); } }