Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/cbor-cose/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ lto = "fat"
codegen-units = 1
strip = true
opt-level = "z"
panic = "abort"
12 changes: 6 additions & 6 deletions rust/cbor-cose/src/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const DEFAULT_FP_URL: &str =
#[allow(dead_code)]
struct FingerprintCache {
/// Map of device codename → fingerprint string.
entries: AHashMap<String, String>,
entries: AHashMap<Box<str>, Box<str>>,
}

/// Parse a fingerprint list from raw text.
Expand Down Expand Up @@ -91,9 +91,9 @@ pub fn fetch_fingerprints(url: Option<&str>) -> Result<usize, String> {
let entries_ref = parse_fingerprints(body);
let count = entries_ref.len();

let entries: AHashMap<String, String> = entries_ref
let entries: AHashMap<Box<str>, Box<str>> = entries_ref
.into_iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.map(|(k, v)| (Box::from(k), Box::from(v)))
.collect();

let cache = FingerprintCache { entries };
Expand All @@ -120,7 +120,7 @@ where
{
let guard = CACHE.read().ok()?;
let cache = guard.as_ref()?;
cache.entries.get(device).map(|s| f(s.as_str()))
cache.entries.get(device).map(|s| f(s.as_ref()))
}

/// Get all cached fingerprints as a list of `"device=fingerprint"` lines.
Expand Down Expand Up @@ -156,9 +156,9 @@ pub fn inject_fingerprints(data: &str) -> usize {
let entries_ref = parse_fingerprints(data);
let count = entries_ref.len();

let entries: AHashMap<String, String> = entries_ref
let entries: AHashMap<Box<str>, Box<str>> = entries_ref
.into_iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.map(|(k, v)| (Box::from(k), Box::from(v)))
.collect();

let cache = FingerprintCache { entries };
Expand Down
6 changes: 3 additions & 3 deletions rust/cbor-cose/src/properties.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use ahash::AHashMap;
use std::sync::RwLock;

static PROPERTIES: RwLock<Option<AHashMap<String, String>>> = RwLock::new(None);
static PROPERTIES: RwLock<Option<AHashMap<Box<str>, Box<str>>>> = RwLock::new(None);

pub fn get_property<R, F: FnOnce(&str) -> R>(name: &str, f: F) -> Option<R> {
// Avoid panics inside Zygote
if let Ok(cache) = PROPERTIES.read() {
cache
.as_ref()
.and_then(|c| c.get(name).map(|s| f(s.as_str())))
.and_then(|c| c.get(name).map(|s| f(s.as_ref())))
} else {
None
}
Expand All @@ -17,7 +17,7 @@ pub fn get_property<R, F: FnOnce(&str) -> R>(name: &str, f: F) -> Option<R> {
pub fn set_property(name: &str, value: &str) {
if let Ok(mut cache) = PROPERTIES.write() {
let map = cache.get_or_insert_with(AHashMap::new);
map.insert(name.to_string(), value.to_string());
map.insert(Box::from(name), Box::from(value));
}
}

Expand Down
Loading