Skip to content

Commit

Permalink
Remove unneeded string clone in L10nManager localize
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperDeSutter committed Jan 14, 2023
1 parent ac5e6d1 commit b8881af
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions druid/src/localization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl L10nManager {
&'args self,
key: &str,
args: impl Into<Option<&'args FluentArgs<'args>>>,
) -> Option<ArcStr> {
) -> Option<Cow<str>> {
let args = args.into();
let value = match self
.current_bundle
Expand All @@ -274,7 +274,7 @@ impl L10nManager {
warn!("localization error {:?}", err);
}

Some(result.into())
Some(result)
}
//TODO: handle locale change
}
Expand Down Expand Up @@ -353,9 +353,16 @@ impl<T> LocalizedString<T> {

self.resolved_lang = Some(manager.current_locale.clone());
let next = manager.localize(self.key, args.as_ref());
let result = next != self.resolved;
self.resolved = next;
result
{
let next = next.as_ref().map(|cow| cow.as_ref());
let prev = self.resolved.as_ref().map(|arc| arc.as_ref());
if next == prev {
// still the same value, no need to update the field
return false;
}
}
self.resolved = next.map(|cow| cow.into());
true
} else {
false
}
Expand Down

0 comments on commit b8881af

Please sign in to comment.