Change unnecessary usage of Arc to borrow instead

Some basic cleanup of function signatures that took ownership of their
parameters, even though they didn't need ownership. Switching over the
usage of `Arc` to a normal borrow has the added benefit of cleaning up
the code a bit since now a reference can be given instead of having to
clone the values. The other benefit is that a lot of clones aren't
necessary anymore. It's not going to have noticable performance
benefits, but it is still a good thing to have less clones all over the
code.
This commit is contained in:
Thomas Frans
2023-03-05 00:02:25 +01:00
committed by GitHub
parent e68f50ddff
commit 98a0596c70
16 changed files with 135 additions and 141 deletions

View File

@@ -52,7 +52,7 @@ impl CommandManager {
config: Arc<Config>,
events: EventManager,
) -> CommandManager {
let bindings = RefCell::new(Self::get_bindings(config.clone()));
let bindings = RefCell::new(Self::get_bindings(&config));
CommandManager {
aliases: HashMap::new(),
bindings,
@@ -64,7 +64,7 @@ impl CommandManager {
}
}
pub fn get_bindings(config: Arc<Config>) -> HashMap<String, Vec<Command>> {
pub fn get_bindings(config: &Config) -> HashMap<String, Vec<Command>> {
let config = config.values();
let mut kb = if config.default_keybindings.unwrap_or(true) {
Self::default_keybindings()
@@ -227,8 +227,7 @@ impl CommandManager {
// update bindings
self.unregister_keybindings(s);
self.bindings
.replace(Self::get_bindings(self.config.clone()));
self.bindings.replace(Self::get_bindings(&self.config));
self.register_keybindings(s);
Ok(None)
}