From e418fa20acbb437eacfcffc27972b7e6a20fb447 Mon Sep 17 00:00:00 2001 From: ghassmo Date: Thu, 7 Oct 2021 09:42:23 +0300 Subject: [PATCH] darkfid: don't clone drk_tokenlist and sol_tokenlist to save allocations --- src/bin/darkfid.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/bin/darkfid.rs b/src/bin/darkfid.rs index 44e8c5116..9f5cd592c 100644 --- a/src/bin/darkfid.rs +++ b/src/bin/darkfid.rs @@ -160,7 +160,7 @@ impl Darkfid { match network { #[cfg(feature = "sol")] NetworkName::Solana => { - let token_id = self.sol_tokenlist.clone().search_id(symbol)?; + let token_id = self.sol_tokenlist.search_id(symbol)?; Ok(json!(token_id)) } #[cfg(feature = "btc")] @@ -228,7 +228,7 @@ impl Darkfid { let network = network.as_str().unwrap(); - let token_id = match assign_id(&network, &token, &self.sol_tokenlist.clone()) { + let token_id = match assign_id(&network, &token, &self.sol_tokenlist) { Ok(t) => t, Err(e) => { return JsonResult::Err(jsonerr(InternalError, Some(e.to_string()), id)); @@ -303,7 +303,7 @@ impl Darkfid { let amount = amount.as_f64().unwrap(); - let decimals = match decimals(network, token, &self.sol_tokenlist.clone()) { + let decimals = match decimals(network, token, &self.sol_tokenlist) { Ok(d) => d, Err(e) => { return JsonResult::Err(jsonerr(InternalError, Some(e.to_string()), id)); @@ -317,7 +317,7 @@ impl Darkfid { } }; - let token_id = match assign_id(&network, &token, &self.sol_tokenlist.clone()) { + let token_id = match assign_id(&network, &token, &self.sol_tokenlist) { Ok(t) => t, Err(e) => { return JsonResult::Err(jsonerr(InternalError, Some(e.to_string()), id)); @@ -336,13 +336,14 @@ impl Darkfid { } } - let hashmap = self.drk_tokenlist.tokens.clone(); + let token_id: &jubjub::Fr; - if hashmap.get(token).is_none() { + // get the id for the token + if let Some(tk_id) = self.drk_tokenlist.tokens.get(token) { + token_id = tk_id; + } else { return JsonResult::Err(jsonerr(InvalidParams, None, id)); } - // get the id for the token - let token_id = hashmap.get(token).unwrap(); // send drk to cashier_public if let JsonResult::Resp(cashier_public) = &rep { @@ -422,13 +423,14 @@ impl Darkfid { } let amount = amount.as_str().unwrap(); - let hashmap = self.drk_tokenlist.tokens.clone(); + let token_id: &jubjub::Fr; - if hashmap.get(token).is_none() { + // get the id for the token + if let Some(tk_id) = self.drk_tokenlist.tokens.get(token) { + token_id = tk_id; + } else { return JsonResult::Err(jsonerr(InvalidParams, None, id)); } - // get the id for the token - let token_id = hashmap.get(token).unwrap(); let result: Result<()> = async { // check if it's in the database