From d8cad12ef5de5c718c7ad4c04fdf72934ea2f3fb Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Thu, 19 Oct 2023 16:35:58 +0200 Subject: [PATCH 1/2] solana-ibc: avoid unnecessary String allocation in Router impl --- solana/solana-ibc/programs/solana-ibc/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index abf4a70c..6b4de80d 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -366,7 +366,8 @@ pub trait SolanaIbcStorageHost { impl Router for SolanaIbcStorage<'_, '_> { // fn get_route(&self, module_id: &ModuleId) -> Option<&dyn Module> { - match module_id.to_string().as_str() { + let module_id = core::borrow::Borrow::borrow(module_id); + match module_id { ibc::applications::transfer::MODULE_ID_STR => { Some(&self.module_holder) } @@ -378,7 +379,8 @@ impl Router for SolanaIbcStorage<'_, '_> { &mut self, module_id: &ModuleId, ) -> Option<&mut dyn Module> { - match module_id.to_string().as_str() { + let module_id = core::borrow::Borrow::borrow(module_id); + match module_id { ibc::applications::transfer::MODULE_ID_STR => { Some(&mut self.module_holder) } From b26c6080299957478e37295faabd64549218dc20 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Thu, 19 Oct 2023 21:01:45 +0200 Subject: [PATCH 2/2] use trait --- solana/solana-ibc/programs/solana-ibc/src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/solana/solana-ibc/programs/solana-ibc/src/lib.rs b/solana/solana-ibc/programs/solana-ibc/src/lib.rs index 6b4de80d..22df375c 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/lib.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/lib.rs @@ -2,6 +2,7 @@ // not much we can do about it. #![allow(clippy::result_large_err)] +use core::borrow::Borrow; use std::collections::BTreeMap; use anchor_lang::prelude::*; @@ -366,8 +367,7 @@ pub trait SolanaIbcStorageHost { impl Router for SolanaIbcStorage<'_, '_> { // fn get_route(&self, module_id: &ModuleId) -> Option<&dyn Module> { - let module_id = core::borrow::Borrow::borrow(module_id); - match module_id { + match module_id.borrow() { ibc::applications::transfer::MODULE_ID_STR => { Some(&self.module_holder) } @@ -379,8 +379,7 @@ impl Router for SolanaIbcStorage<'_, '_> { &mut self, module_id: &ModuleId, ) -> Option<&mut dyn Module> { - let module_id = core::borrow::Borrow::borrow(module_id); - match module_id { + match module_id.borrow() { ibc::applications::transfer::MODULE_ID_STR => { Some(&mut self.module_holder) }