From f0bc62ce191ae6e0011c3a95c9f71b6e7a9ec47b Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 12 Jun 2022 18:18:26 +0200 Subject: [PATCH] Minor optimization in StringKey, making it from an Arc into an Arc --- src/utils/string_key.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/string_key.rs b/src/utils/string_key.rs index b701648..7c89902 100644 --- a/src/utils/string_key.rs +++ b/src/utils/string_key.rs @@ -8,12 +8,12 @@ use std::sync::{Arc, Mutex, Weak}; /// `charmander` == `Charmander`. #[derive(Clone, Debug)] pub struct StringKey { - str: Arc, + str: Arc, hash: u32, } lazy_static::lazy_static! { - static ref STRING_CACHE: Mutex>> = Mutex::new(HashMap::new()); + static ref STRING_CACHE: Mutex>> = Mutex::new(HashMap::new()); } impl StringKey { @@ -49,7 +49,7 @@ impl StringKey { } } let v = Self { - str: Arc::new(s.to_string()), + str: s.into(), hash, }; cache.insert(hash, Arc::downgrade(&v.str)); @@ -57,7 +57,7 @@ impl StringKey { } pub fn str(&self) -> &str { - self.str.as_str() + &self.str } pub fn hash(&self) -> u32 {