Import hashmap entry

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2023-05-22 17:49:06 +03:00
parent 5a04b21f7a
commit 414061591a
+6 -3
View File
@@ -2,7 +2,10 @@ use futures::stream::StreamExt;
use futures_util::future::{self, Either};
use serde::Deserialize;
use serde_json::value::RawValue;
use std::{collections::HashMap, str::FromStr};
use std::{
collections::{hash_map::Entry, HashMap},
str::FromStr,
};
use tokio::sync::{mpsc, oneshot};
///! The background task of the light client.
@@ -137,7 +140,7 @@ impl BackgroundTask {
// because it sees it as used on both closures and apparently cannot determine that only one
// closure can be executed.
match self.subscriptions_cache.entry(id) {
std::collections::hash_map::Entry::Occupied(mut entry) => {
Entry::Occupied(mut entry) => {
let cached_responses: &mut Vec<_> = entry.get_mut();
// Do not cache notification if exceeded capacity.
if cached_responses.len() > BUFFER_NUM_NOTIFICATIONS {
@@ -146,7 +149,7 @@ impl BackgroundTask {
cached_responses.push(result);
}
std::collections::hash_map::Entry::Vacant(entry) => {
Entry::Vacant(entry) => {
let mut vec = Vec::with_capacity(BUFFER_NUM_NOTIFICATIONS);
vec.push(result);
entry.insert(vec);