Skip to content

Commit 9068eb7

Browse files
bors[bot]cuviper
andcommitted
Merge #58
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 <[email protected]>
2 parents a40659f + e45b08d commit 9068eb7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,9 +2436,9 @@ where
24362436
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
24372437
let iter = iter.into_iter();
24382438
let mut map = Self::with_capacity_and_hasher(iter.size_hint().0, S::default());
2439-
for (k, v) in iter {
2439+
iter.for_each(|(k, v)| {
24402440
map.insert(k, v);
2441-
}
2441+
});
24422442
map
24432443
}
24442444
}
@@ -2461,9 +2461,9 @@ where
24612461
(iter.size_hint().0 + 1) / 2
24622462
};
24632463
self.reserve(reserve);
2464-
for (k, v) in iter {
2464+
iter.for_each(move |(k, v)| {
24652465
self.insert(k, v);
2466-
}
2466+
});
24672467
}
24682468
}
24692469

0 commit comments

Comments
 (0)