Skip to content

Commit

Permalink
Use retain in ItemMap::filter
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper authored and emilio committed Apr 14, 2024
1 parent f1d5801 commit bde8ab4
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions src/bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,13 @@ impl<T: Item + Clone> ItemMap<T> {
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<F>(&self, mut callback: F)
Expand Down

0 comments on commit bde8ab4

Please sign in to comment.