Skip to content

Commit

Permalink
Reduce unnecessary memory copying (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
yk0n9 authored Aug 20, 2024
1 parent 4e21836 commit 5d4b561
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/support/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,15 @@ impl SimpleBackend {
/// ```
pub fn add_translations(&mut self, locale: &str, data: &HashMap<&str, &str>) {
let data = data
.clone()
.into_iter()
.map(|(k, v)| (k.into(), v.into()))
.iter()
.map(|(k, v)| ((*k).into(), (*v).into()))
.collect::<HashMap<_, _>>();

if let Some(trs) = self.translations.get_mut(locale) {
trs.extend(data.clone());
} else {
self.translations.insert(locale.into(), data.clone());
}
let trs = self
.translations
.entry(locale.into())
.or_insert(HashMap::new());
trs.extend(data);
}
}

Expand Down

0 comments on commit 5d4b561

Please sign in to comment.