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