File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -1387,6 +1387,17 @@ impl<T> FromIterator<T> for Vec<T> {
13871387 let ( lower, _) = iterator. size_hint ( ) ;
13881388 let mut vector = Vec :: with_capacity ( lower) ;
13891389
1390+ // This function should be the moral equivalent of:
1391+ //
1392+ // for item in iterator {
1393+ // vector.push(item);
1394+ // }
1395+ //
1396+ // This equivalent crucially runs the iterator precisely once. The
1397+ // optimization below (eliding bound/growth checks) means that we
1398+ // actually run the iterator twice. To ensure the "moral equivalent" we
1399+ // do a `fuse()` operation to ensure that the iterator continues to
1400+ // return `None` after seeing the first `None`.
13901401 let mut i = iterator. fuse ( ) ;
13911402 for element in i. by_ref ( ) . take ( vector. capacity ( ) ) {
13921403 let len = vector. len ( ) ;
You can’t perform that action at this time.
0 commit comments