Use for_each to extend collections
This updates the `Extend` implementations to use `for_each` for many collections: `BinaryHeap`, `BTreeMap`, `BTreeSet`, `LinkedList`, `Path`, `TokenStream`, `VecDeque`, and `Wtf8Buf`. Folding with `for_each` enables better performance than a `for`-loop for some iterators, especially if they can just forward to internal iterators, like `Chain` and `FlatMap` do.
This commit is contained in:
@@ -1551,9 +1551,7 @@ impl<P: AsRef<Path>> iter::FromIterator<P> for PathBuf {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<P: AsRef<Path>> iter::Extend<P> for PathBuf {
|
||||
fn extend<I: IntoIterator<Item = P>>(&mut self, iter: I) {
|
||||
for p in iter {
|
||||
self.push(p.as_ref())
|
||||
}
|
||||
iter.into_iter().for_each(move |p| self.push(p.as_ref()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user