This commit is contained in:
@@ -42,8 +42,7 @@ impl StringKey {
|
||||
/// Creates a new StringKey. If we can find a value for this StringKey in the cache, we re-use
|
||||
/// that value.
|
||||
pub fn new(s: &str) -> Self {
|
||||
let s: ArcStr = s.into();
|
||||
let hash = StringKey::get_hash(s.as_str());
|
||||
let hash = Self::get_hash(s);
|
||||
{
|
||||
let cache_read = STRING_CACHE.read();
|
||||
let cached_value = cache_read.get(&hash);
|
||||
@@ -55,8 +54,15 @@ impl StringKey {
|
||||
}
|
||||
}
|
||||
{
|
||||
let v = Self { str: s.clone(), hash };
|
||||
let mut cache_write = STRING_CACHE.write();
|
||||
if let Some(cached_value) = cache_write.get(&hash) {
|
||||
return Self {
|
||||
str: cached_value.clone(),
|
||||
hash,
|
||||
};
|
||||
}
|
||||
let s: ArcStr = s.into();
|
||||
let v = Self { str: s.clone(), hash };
|
||||
cache_write.insert(hash, s);
|
||||
v
|
||||
}
|
||||
@@ -112,7 +118,7 @@ impl Display for StringKey {
|
||||
|
||||
impl Into<StringKey> for &CStr {
|
||||
fn into(self) -> StringKey {
|
||||
StringKey::new(self.to_str().unwrap().into())
|
||||
StringKey::new(self.to_str().unwrap())
|
||||
}
|
||||
}
|
||||
/// Converts a character to lowercased in a const safe way.
|
||||
|
||||
Reference in New Issue
Block a user