Skip to content

Commit ce02330

Browse files
committed
Avoid index fixups in sorted_by
1 parent 4fbcf36 commit ce02330

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/map.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,15 @@ where
568568
/// the key-value pairs with the result.
569569
///
570570
/// The sort is stable.
571-
pub fn sorted_by<F>(mut self, mut cmp: F) -> IntoIter<K, V>
571+
pub fn sorted_by<F>(self, mut cmp: F) -> IntoIter<K, V>
572572
where
573573
F: FnMut(&K, &V, &K, &V) -> Ordering,
574574
{
575-
self.as_entries_mut()
576-
.sort_by(move |a, b| cmp(&a.key, &a.value, &b.key, &b.value));
577-
self.into_iter()
575+
let mut entries = self.into_entries();
576+
entries.sort_by(move |a, b| cmp(&a.key, &a.value, &b.key, &b.value));
577+
IntoIter {
578+
iter: entries.into_iter(),
579+
}
578580
}
579581

580582
/// Clears the `IndexMap`, returning all key-value pairs as a drain iterator.

0 commit comments

Comments
 (0)