Initial work on FFI
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-09-18 18:02:13 +02:00
parent 39497891e9
commit 726e294f11
19 changed files with 814 additions and 26 deletions

View File

@@ -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.