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:
Josh Stone
2019-04-05 14:51:07 -07:00
parent acd8dd6a50
commit 0730a01c5c
8 changed files with 10 additions and 22 deletions

View File

@@ -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));
}
}