refac(rust): use hashmap entry for in-place manipulation

This commit is contained in:
Dmitriy Pleshevskiy 2021-10-29 11:12:45 +03:00
parent 2adc74168d
commit 7c6d9ae21d
1 changed files with 1 additions and 1 deletions

View File

@ -4,7 +4,7 @@ fn count_duplicates(text: &str) -> u32 {
text.to_lowercase()
.chars()
.fold(HashMap::<char, u32>::new(), |mut hm, c| {
hm.insert(c, hm.get(&c).copied().unwrap_or_default() + 1);
(*hm.entry(c).or_default()) += 1;
hm
})
.values()