Skip to content

Commit

Permalink
Merge #58
Browse files Browse the repository at this point in the history
58: Use for_each in map Extend and FromIterator r=Amanieu a=cuviper

Using `for_each` allows internal iteration, which can have better
performance for some iterators. For instance, `Chain` and `FlatMap` have
to check their state every time `next()` is called, but when folding
they can just forward to their inner iterators.

Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
bors[bot] and cuviper committed Apr 5, 2019
2 parents a40659f + e45b08d commit 9068eb7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2436,9 +2436,9 @@ where
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
let iter = iter.into_iter();
let mut map = Self::with_capacity_and_hasher(iter.size_hint().0, S::default());
for (k, v) in iter {
iter.for_each(|(k, v)| {
map.insert(k, v);
}
});
map
}
}
Expand All @@ -2461,9 +2461,9 @@ where
(iter.size_hint().0 + 1) / 2
};
self.reserve(reserve);
for (k, v) in iter {
iter.for_each(move |(k, v)| {
self.insert(k, v);
}
});
}
}

Expand Down

0 comments on commit 9068eb7

Please sign in to comment.