Skip to content

Commit 4fbcf36

Browse files
committed
Simplify calls to find_existing_entry
1 parent 8d1fa53 commit 4fbcf36

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/map.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -622,13 +622,9 @@ impl<K, V, S> IndexMap<K, V, S> {
622622
///
623623
/// Computes in **O(1)** time (average).
624624
pub fn swap_remove_index(&mut self, index: usize) -> Option<(K, V)> {
625-
let (probe, found) = match self
626-
.as_entries()
627-
.get(index)
628-
.map(|e| self.core.find_existing_entry(e))
629-
{
625+
let (probe, found) = match self.as_entries().get(index) {
626+
Some(e) => self.core.find_existing_entry(e),
630627
None => return None,
631-
Some(t) => t,
632628
};
633629
Some(self.core.swap_remove_found(probe, found))
634630
}
@@ -643,13 +639,9 @@ impl<K, V, S> IndexMap<K, V, S> {
643639
///
644640
/// Computes in **O(n)** time (average).
645641
pub fn shift_remove_index(&mut self, index: usize) -> Option<(K, V)> {
646-
let (probe, found) = match self
647-
.as_entries()
648-
.get(index)
649-
.map(|e| self.core.find_existing_entry(e))
650-
{
642+
let (probe, found) = match self.as_entries().get(index) {
643+
Some(e) => self.core.find_existing_entry(e),
651644
None => return None,
652-
Some(t) => t,
653645
};
654646
Some(self.core.shift_remove_found(probe, found))
655647
}

src/map_core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,9 @@ impl<K, V> IndexMapCore<K, V> {
572572
}
573573

574574
pub(crate) fn pop_impl(&mut self) -> Option<(K, V)> {
575-
let (probe, found) = match self.entries.last().map(|e| self.find_existing_entry(e)) {
575+
let (probe, found) = match self.as_entries().last() {
576+
Some(e) => self.find_existing_entry(e),
576577
None => return None,
577-
Some(t) => t,
578578
};
579579
debug_assert_eq!(found, self.entries.len() - 1);
580580
Some(self.swap_remove_found(probe, found))

0 commit comments

Comments
 (0)