From 771e2f55c2fb8edd98e3c90822a2cdae92cc96ce Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 14 Mar 2024 16:41:16 -0700 Subject: [PATCH] Use `retain` in `ItemMap::filter` --- src/bindgen/ir/item.rs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/bindgen/ir/item.rs b/src/bindgen/ir/item.rs index 16d98f55d..e5281aed9 100644 --- a/src/bindgen/ir/item.rs +++ b/src/bindgen/ir/item.rs @@ -158,28 +158,15 @@ impl ItemMap { where F: Fn(&T) -> bool, { - let data = mem::take(&mut self.data); - - for (name, container) in data { - match container { - ItemValue::Cfg(items) => { - let mut new_items = Vec::new(); - for item in items { - if !callback(&item) { - new_items.push(item); - } - } - if !new_items.is_empty() { - self.data.insert(name, ItemValue::Cfg(new_items)); - } - } - ItemValue::Single(item) => { - if !callback(&item) { - self.data.insert(name, ItemValue::Single(item)); - } + self.data.retain(|_, container| { + match *container { + ItemValue::Cfg(ref mut items) => { + items.retain(|item| !callback(item)); + !items.is_empty() } + ItemValue::Single(ref item) => !callback(item), } - } + }); } pub fn for_all_items(&self, mut callback: F)