1
Fork 0

Iterate over the smaller list

If there are two lists of different sizes,
iterating over the smaller list and then
looking up in the larger list is cheaper
than vice versa, because lookups scale
sublinearly.
This commit is contained in:
est31 2020-10-24 15:54:19 +02:00
parent 4d247ad7d3
commit a21c2eb121
2 changed files with 12 additions and 0 deletions

View file

@ -265,6 +265,10 @@ impl<'tcx> AssociatedItems<'tcx> {
self.items.iter().map(|(_, v)| *v)
}
pub fn len(&self) -> usize {
self.items.len()
}
/// Returns an iterator over all associated items with the given name, ignoring hygiene.
pub fn filter_by_name_unhygienic(
&self,