From 638848fcff9d05b633cc0f52e8f40f336da5518b Mon Sep 17 00:00:00 2001 From: Damian Barabonkov Date: Tue, 10 Feb 2026 12:23:28 -0800 Subject: [PATCH] pci: Accept MmioRegion reference in has_matching_slots() Change has_matching_slots() to compare two MmioRegion instances directly rather than requiring callers to construct an intermediate HashSet of slot numbers. Remove the now-unused user_memory_region_slots() method and HashSet import. Signed-off-by: Damian Barabonkov --- pci/src/vfio.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pci/src/vfio.rs b/pci/src/vfio.rs index 914feaffd..9e8e7e316 100644 --- a/pci/src/vfio.rs +++ b/pci/src/vfio.rs @@ -276,6 +276,17 @@ pub struct MmioRegion { pub(crate) user_memory_regions: Vec, } +impl MmioRegion { + /// Returns true if this region has the exact same memory slots as the other region. + pub fn has_matching_slots(&self, other: &MmioRegion) -> bool { + self.user_memory_regions.len() == other.user_memory_regions.len() + && self + .user_memory_regions + .iter() + .all(|u| other.user_memory_regions.iter().any(|o| o.slot == u.slot)) + } +} + /// # Safety /// /// [`Self::find_user_address`] must always either return `Err`