From 7c6d9ae21db4f6342db6f30c8e6a56cbeebc971e Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 29 Oct 2021 11:12:45 +0300 Subject: [PATCH] refac(rust): use hashmap entry for in-place manipulation --- rust/tests/2_counting_duplicates.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/tests/2_counting_duplicates.rs b/rust/tests/2_counting_duplicates.rs index 7dfa766..c36637e 100644 --- a/rust/tests/2_counting_duplicates.rs +++ b/rust/tests/2_counting_duplicates.rs @@ -4,7 +4,7 @@ fn count_duplicates(text: &str) -> u32 { text.to_lowercase() .chars() .fold(HashMap::::new(), |mut hm, c| { - hm.insert(c, hm.get(&c).copied().unwrap_or_default() + 1); + (*hm.entry(c).or_default()) += 1; hm }) .values()