Minor optimization in StringKey, making it from an Arc<String> into an Arc<str>
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
55380f631f
commit
f0bc62ce19
|
@ -8,12 +8,12 @@ use std::sync::{Arc, Mutex, Weak};
|
|||
/// `charmander` == `Charmander`.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct StringKey {
|
||||
str: Arc<String>,
|
||||
str: Arc<str>,
|
||||
hash: u32,
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref STRING_CACHE: Mutex<HashMap<u32, Weak<String>>> = Mutex::new(HashMap::new());
|
||||
static ref STRING_CACHE: Mutex<HashMap<u32, Weak<str>>> = 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 {
|
||||
|
|
Loading…
Reference in New Issue