Skip to content

Commit

Permalink
functions on Entry instead of match
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinquaXD committed Dec 20, 2024
1 parent e7530af commit ade2360
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions crates/driver/src/domain/competition/bad_tokens/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ impl Cache {

/// Updates whether or not a token should be considered supported.
pub fn update_quality(&self, token: eth::TokenAddress, quality: Quality, now: Instant) {
match self.0.cache.entry(token) {
Entry::Occupied(mut o) => {
let value = o.get_mut();
self.0
.cache
.entry(token)
.and_modify(|value| {
if quality == Quality::Unsupported
|| now.duration_since(value.timestamp) > self.0.max_age
{
Expand All @@ -52,14 +53,11 @@ impl Cache {
value.quality = quality;
}
value.timestamp = now;
}
Entry::Vacant(v) => {
v.insert(CacheEntry {
quality,
timestamp: now,
});
}
}
})
.or_insert_with(|| CacheEntry {
quality,
timestamp: now,
});
}

pub fn evict_outdated_entries(&self) {
Expand Down

0 comments on commit ade2360

Please sign in to comment.