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:
@@ -388,9 +388,7 @@ impl Extend<CodePoint> for Wtf8Buf {
|
||||
let (low, _high) = iterator.size_hint();
|
||||
// Lower bound of one byte per code point (ASCII only)
|
||||
self.bytes.reserve(low);
|
||||
for code_point in iterator {
|
||||
self.push(code_point);
|
||||
}
|
||||
iterator.for_each(move |code_point| self.push(code_point));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user