Remove unnecessary clones

master
Amanda Graven 2021-01-11 14:12:11 +01:00 committed by Damir Jelić
parent 077c20ed74
commit 9efece4f7a
1 changed files with 46 additions and 54 deletions

View File

@ -221,26 +221,20 @@ impl Room {
/// [spec]:
/// <https://matrix.org/docs/spec/client_server/latest#calculating-the-display-name-for-a-room>
async fn calculate_name(&self) -> String {
let name;
let alias;
{
let summary = {
let inner = self.inner.read().unwrap();
name = inner.base_info.name.clone();
alias = inner.base_info.canonical_alias.clone();
}
if let Some(name) = name {
if let Some(name) = &inner.base_info.name {
let name = name.trim();
name.to_string()
} else if let Some(alias) = alias {
return name.to_string();
} else if let Some(alias) = &inner.base_info.canonical_alias {
let alias = alias.alias().trim();
alias.to_string()
} else {
return alias.to_string();
}
inner.summary.clone()
};
// TODO what should we do here? We have correct counts only if lazy
// loading is used.
let summary = { self.inner.read().unwrap().summary.clone() };
let joined = summary.joined_member_count;
let invited = summary.invited_member_count;
let heroes_count = summary.heroes.len() as u64;
@ -274,13 +268,11 @@ impl Room {
summary.heroes
);
self.inner
.read()
.unwrap()
let inner = self.inner.read().unwrap();
inner
.base_info
.calculate_room_name(joined, invited, members)
}
}
pub(crate) fn clone_info(&self) -> RoomInfo {
(*self.inner.read().unwrap()).clone()