Skip to content

Commit 948e448

Browse files
authored
Rollup merge of #143111 - xu-cheng:btreeset_from_iter, r=Mark-Simulacrum
BTreeSet: remove duplicated code by reusing `from_sorted_iter` The method `BTreeSet::from_sorted_iter` was introduced in 49ccb75, but it was not consistently used throughout the codebase. As a result, some code redundantly reimplemented its logic. This commit fixes the problem.
2 parents 6c3162d + cd1713e commit 948e448

File tree

1 file changed

+1
-3
lines changed
  • library/alloc/src/collections/btree

1 file changed

+1
-3
lines changed

library/alloc/src/collections/btree/set.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,9 +1517,7 @@ impl<T: Ord, const N: usize> From<[T; N]> for BTreeSet<T> {
15171517

15181518
// use stable sort to preserve the insertion order.
15191519
arr.sort();
1520-
let iter = IntoIterator::into_iter(arr).map(|k| (k, SetValZST::default()));
1521-
let map = BTreeMap::bulk_build_from_sorted_iter(iter, Global);
1522-
BTreeSet { map }
1520+
BTreeSet::from_sorted_iter(IntoIterator::into_iter(arr), Global)
15231521
}
15241522
}
15251523

0 commit comments

Comments
 (0)