diff --git a/pineappl/src/grid.rs b/pineappl/src/grid.rs index 7f6ea093..0224c30c 100644 --- a/pineappl/src/grid.rs +++ b/pineappl/src/grid.rs @@ -937,31 +937,24 @@ impl Grid { bins: &BinLimits, entries: &[LumiEntry], ) -> (Vec, Vec) { - let mut new_orders: Vec = Vec::new(); - let new_bins = bins.bins() - self.bin_limits.bins(); - let mut new_entries: Vec = Vec::new(); + fn unique(current: &[T], update: &[T]) -> Vec { + let mut new = Vec::new(); - for order in orders.iter() { - if !self - .orders - .iter() - .chain(new_orders.iter()) - .any(|x| x == order) - { - new_orders.push(order.clone()); + for el in update.iter() { + if !current + .iter() + .chain(new.iter()) + .any(|x| x == el) + { + new.push((*el).clone()); + } } + new } - for entry in entries.iter() { - if !self - .lumi - .iter() - .chain(new_entries.iter()) - .any(|y| y == entry) - { - new_entries.push(entry.clone()); - } - } + let mut new_orders = unique(&self.orders, &orders); + let new_bins = bins.bins() - self.bin_limits.bins(); + let mut new_entries = unique(&self.lumi, &entries); if !new_orders.is_empty() || !new_entries.is_empty() || (new_bins != 0) { self.increase_shape(&(new_orders.len(), new_bins, new_entries.len()));