Skip to content

Commit 5d4b561

Browse files
authored
Reduce unnecessary memory copying (#89)
1 parent 4e21836 commit 5d4b561

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

crates/support/src/backend.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,15 @@ impl SimpleBackend {
7070
/// ```
7171
pub fn add_translations(&mut self, locale: &str, data: &HashMap<&str, &str>) {
7272
let data = data
73-
.clone()
74-
.into_iter()
75-
.map(|(k, v)| (k.into(), v.into()))
73+
.iter()
74+
.map(|(k, v)| ((*k).into(), (*v).into()))
7675
.collect::<HashMap<_, _>>();
7776

78-
if let Some(trs) = self.translations.get_mut(locale) {
79-
trs.extend(data.clone());
80-
} else {
81-
self.translations.insert(locale.into(), data.clone());
82-
}
77+
let trs = self
78+
.translations
79+
.entry(locale.into())
80+
.or_insert(HashMap::new());
81+
trs.extend(data);
8382
}
8483
}
8584

0 commit comments

Comments
 (0)