Skip to content

Commit a1b13d6

Browse files
committed
Fix rust-lang/rust#59159 in delete
1 parent 0847afc commit a1b13d6

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/util/counter.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ impl<T: Hash + Eq + PartialEq + Clone + Display> Counter<T> {
6060
}
6161

6262
/// Remove an item from the internal order store
63-
fn purge_from_order(&mut self, item: &T, count: u64) {
64-
if let Some(order) = self.order.get_mut(&count) {
63+
fn purge_from_order(&mut self, item: &T, count: &u64) {
64+
if let Some(order) = self.order.get_mut(count) {
6565
// If there was data there, remove the existing item
6666
if !order.is_empty() {
6767
order.retain(|i| i != item);
6868
if order.is_empty() {
69-
self.order.remove(&count);
69+
self.order.remove(count);
7070
}
7171
};
7272
};
@@ -78,7 +78,7 @@ impl<T: Hash + Eq + PartialEq + Clone + Display> Counter<T> {
7878

7979
/// Update the internal item order HashMap
8080
fn update_order(&mut self, item: T, old_count: &u64, new_count: &u64) {
81-
self.purge_from_order(&item, *old_count);
81+
self.purge_from_order(&item, old_count);
8282
match self.order.get_mut(new_count) {
8383
Some(v) => {
8484
v.push(item);
@@ -91,7 +91,7 @@ impl<T: Hash + Eq + PartialEq + Clone + Display> Counter<T> {
9191

9292
/// Increment an item into the counter, creating if it does not exist
9393
fn increment(&mut self, item: T) {
94-
let old_count = *self.state.get(&item).unwrap_or(&0);
94+
let old_count = self.state.get(&item).unwrap_or(&0).to_owned();
9595
let new_count = old_count.checked_add(1);
9696
match new_count {
9797
Some(count) => self.state.insert(item.to_owned(), count),
@@ -102,7 +102,7 @@ impl<T: Hash + Eq + PartialEq + Clone + Display> Counter<T> {
102102

103103
/// Reduce an item from the counter, removing if it becomes 0
104104
fn decrement(&mut self, item: T) {
105-
let old_count = *self.state.get(&item).unwrap_or(&0);
105+
let old_count = self.state.get(&item).unwrap_or(&0).to_owned();
106106
let new_count = old_count.checked_sub(1);
107107
match new_count {
108108
Some(count) => {
@@ -121,10 +121,9 @@ impl<T: Hash + Eq + PartialEq + Clone + Display> Counter<T> {
121121

122122
/// Remove an item from the counter completely
123123
fn delete(&mut self, item: &T) {
124-
if let Some(count) = self.state.get(item) {
125-
self.purge_from_order(item, *count);
126-
self.purge_from_state(item);
127-
}
124+
let count = self.state.get(item).unwrap().to_owned();
125+
self.purge_from_order(item, &count);
126+
self.purge_from_state(item);
128127
}
129128
}
130129

0 commit comments

Comments
 (0)