Skip to content

Commit d8e3545

Browse files
committed
Avoid index fixups in sorted_by
1 parent 26b9372 commit d8e3545

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/map.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,13 +559,15 @@ where
559559
/// the key-value pairs with the result.
560560
///
561561
/// The sort is stable.
562-
pub fn sorted_by<F>(mut self, mut cmp: F) -> IntoIter<K, V>
562+
pub fn sorted_by<F>(self, mut cmp: F) -> IntoIter<K, V>
563563
where
564564
F: FnMut(&K, &V, &K, &V) -> Ordering,
565565
{
566-
self.as_entries_mut()
567-
.sort_by(move |a, b| cmp(&a.key, &a.value, &b.key, &b.value));
568-
self.into_iter()
566+
let mut entries = self.into_entries();
567+
entries.sort_by(move |a, b| cmp(&a.key, &a.value, &b.key, &b.value));
568+
IntoIter {
569+
iter: entries.into_iter(),
570+
}
569571
}
570572

571573
/// Reverses the order of the map’s key-value pairs in place.

0 commit comments

Comments
 (0)