From 94be4d2578d310b0331f0669a43413bc15bfc71d Mon Sep 17 00:00:00 2001 From: projectmoon Date: Sun, 7 Feb 2021 21:16:58 +0000 Subject: [PATCH] Avoid key clone when deleting variables. Minor db code cleanup. --- src/db/variables.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/db/variables.rs b/src/db/variables.rs index 8d2be34..1c3834c 100644 --- a/src/db/variables.rs +++ b/src/db/variables.rs @@ -21,7 +21,7 @@ pub struct Variables { pub(in crate::db) room_user_variable_count: Tree, } -/// Request soemthing by a username and room ID. +/// Request something by a username and room ID. pub struct UserAndRoom<'a>(pub &'a str, pub &'a str); fn to_vec(value: &UserAndRoom<'_>) -> Vec { @@ -83,7 +83,7 @@ impl Variables { prefix.push(0xff); let prefix_len: usize = prefix.len(); - let variables: Result, DataError> = self + let variables: Result, DataError> = self .room_user_variables .scan_prefix(prefix) .map(|entry| match entry { @@ -96,7 +96,8 @@ impl Variables { }) .collect(); - //Convert I32 to hash map. collect() inferred via return type. + // Convert tuples to hash map with collect(), inferred via + // return type. variables.map(|entries| entries.into_iter().collect()) } @@ -168,8 +169,7 @@ impl Variables { key.push(0xff); key.extend_from_slice(variable_name.as_bytes()); - //TODO why does tx.remove require moving the key? - if let Some(_) = tx_vars.remove(key.clone())? { + if let Some(_) = tx_vars.remove(key)? { if let Err(e) = alter_room_variable_count(&tx_counts, user_and_room, -1) { return abort(e); }