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 49ccb7519f, but it was not consistently used throughout the codebase. As a result, some code redundantly reimplemented its logic. This commit fixes the problem.
This commit is contained in:
Matthias Krüger 2025-06-28 22:05:33 +02:00 committed by GitHub
commit dc08a0add8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1517,9 +1517,7 @@ impl<T: Ord, const N: usize> From<[T; N]> for BTreeSet<T> {
// use stable sort to preserve the insertion order.
arr.sort();
let iter = IntoIterator::into_iter(arr).map(|k| (k, SetValZST::default()));
let map = BTreeMap::bulk_build_from_sorted_iter(iter, Global);
BTreeSet { map }
BTreeSet::from_sorted_iter(IntoIterator::into_iter(arr), Global)
}
}