Skip to content

Commit

Permalink
refactore: use clone_from() (#5451)
Browse files Browse the repository at this point in the history
`a.clone_from(&b)` is equivalent to `a = b.clone()` in functionality,
but can be overridden to reuse the resources of a to avoid unnecessary
allocations.
  • Loading branch information
Septias authored Apr 10, 2024
1 parent a3b62b9 commit b47cad7
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ impl Chat {
Ok(contacts) => {
if let Some(contact_id) = contacts.first() {
if let Ok(contact) = Contact::get_by_id(context, *contact_id).await {
chat_name = contact.get_display_name().to_owned();
contact.get_display_name().clone_into(&mut chat_name);
}
}
}
Expand Down Expand Up @@ -2861,7 +2861,7 @@ pub(crate) async fn create_send_msg_jobs(context: &Context, msg: &mut Message) -
msg.update_param(context).await?;
}

msg.subject = rendered_msg.subject.clone();
msg.subject.clone_from(&rendered_msg.subject);
msg.update_subject(context).await?;
let chunk_size = context
.get_configured_provider()
Expand Down
8 changes: 4 additions & 4 deletions src/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ async fn configure(ctx: &Context, param: &mut LoginParam) -> Result<()> {
let mut smtp_configured = false;
let mut errors = Vec::new();
for smtp_server in smtp_servers {
smtp_param.user = smtp_server.username.clone();
smtp_param.server = smtp_server.hostname.clone();
smtp_param.user.clone_from(&smtp_server.username);
smtp_param.server.clone_from(&smtp_server.hostname);
smtp_param.port = smtp_server.port;
smtp_param.security = smtp_server.socket;
smtp_param.certificate_checks = match smtp_server.strict_tls {
Expand Down Expand Up @@ -403,8 +403,8 @@ async fn configure(ctx: &Context, param: &mut LoginParam) -> Result<()> {
let imap_servers_count = imap_servers.len();
let mut errors = Vec::new();
for (imap_server_index, imap_server) in imap_servers.into_iter().enumerate() {
param.imap.user = imap_server.username.clone();
param.imap.server = imap_server.hostname.clone();
param.imap.user.clone_from(&imap_server.username);
param.imap.server.clone_from(&imap_server.hostname);
param.imap.port = imap_server.port;
param.imap.security = imap_server.socket;
param.imap.certificate_checks = match imap_server.strict_tls {
Expand Down
4 changes: 2 additions & 2 deletions src/imap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl Imap {
Ok(session) => {
// Store server ID in the context to display in account info.
let mut lock = context.server_id.write().await;
*lock = session.capabilities.server_id.clone();
lock.clone_from(&session.capabilities.server_id);

self.login_failed_once = false;
context.emit_event(EventType::ImapConnected(format!(
Expand Down Expand Up @@ -420,7 +420,7 @@ impl Imap {
drop(lock);

let mut msg = Message::new(Viewtype::Text);
msg.text = message.clone();
msg.text.clone_from(&message);
if let Err(e) =
chat::add_device_msg_with_importance(context, None, Some(&mut msg), true)
.await
Expand Down
2 changes: 1 addition & 1 deletion src/login_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl LoginParam {
// Only check for IMAP password, SMTP password is an "advanced" setting.
ensure!(!param.imap.password.is_empty(), "Missing (IMAP) password.");
if param.smtp.password.is_empty() {
param.smtp.password = param.imap.password.clone()
param.smtp.password.clone_from(&param.imap.password)
}
Ok(param)
}
Expand Down
2 changes: 1 addition & 1 deletion src/mimeparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ impl MimeMessage {
let mut filepart = self.parts.swap_remove(1);

// insert new one
filepart.msg = self.parts[0].msg.clone();
filepart.msg.clone_from(&self.parts[0].msg);
if let Some(quote) = self.parts[0].param.get(Param::Quote) {
filepart.param.set(Param::Quote, quote);
}
Expand Down
2 changes: 1 addition & 1 deletion src/peerstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ pub(crate) async fn maybe_do_aeap_transition(
.await?;

let old_addr = mem::take(&mut peerstate.addr);
peerstate.addr = info.from.clone();
peerstate.addr.clone_from(&info.from);
let header = info.autocrypt_header.as_ref().context(
"Internal error: Tried to do an AEAP transition without an autocrypt header??",
)?;
Expand Down
6 changes: 3 additions & 3 deletions src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ async fn apply_group_changes(
} else if let Some(added_id) = added_id {
diff.insert(added_id);
}
new_members = chat_contacts.clone();
new_members.clone_from(&chat_contacts);
// Don't delete any members locally, but instead add absent ones to provide group
// membership consistency for all members:
// - Classical MUA users usually don't intend to remove users from an email thread, so
Expand Down Expand Up @@ -2268,7 +2268,7 @@ fn compute_mailinglist_name(
// and we can detect these lists by a unique `ListId`-suffix.
if listid.ends_with(".list-id.mcsv.net") {
if let Some(display_name) = &mime_parser.from.display_name {
name = display_name.clone();
name.clone_from(display_name);
}
}

Expand Down Expand Up @@ -2296,7 +2296,7 @@ fn compute_mailinglist_name(
|| listid.ends_with(".xt.local"))
{
if let Some(display_name) = &mime_parser.from.display_name {
name = display_name.clone();
name.clone_from(display_name);
}
}

Expand Down

0 comments on commit b47cad7

Please sign in to comment.