From 083871447d7c926fbf2b4bfe20efac7cfbf46ce8 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 30 Dec 2024 11:01:58 -0600 Subject: [PATCH] perf(dictgen): Make lookups faster for map/table --- crates/dictgen/src/map.rs | 2 ++ crates/dictgen/src/table.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/crates/dictgen/src/map.rs b/crates/dictgen/src/map.rs index f6a3260..e5b9fd9 100644 --- a/crates/dictgen/src/map.rs +++ b/crates/dictgen/src/map.rs @@ -58,6 +58,7 @@ pub struct DictMap { } impl DictMap { + #[inline] pub fn find(&self, word: &'_ unicase::UniCase<&str>) -> Option<&V> { if self.range.contains(&word.len()) { self.map.get(&(*word).into()) @@ -66,6 +67,7 @@ impl DictMap { } } + #[inline] pub fn iter(&self) -> impl Iterator, &V)> + '_ { self.map.entries().map(|(k, v)| (k.convert(), v)) } diff --git a/crates/dictgen/src/table.rs b/crates/dictgen/src/table.rs index 539f6ac..588d39f 100644 --- a/crates/dictgen/src/table.rs +++ b/crates/dictgen/src/table.rs @@ -59,6 +59,7 @@ pub struct DictTable { } impl DictTable { + #[inline] pub fn find(&self, word: &'_ unicase::UniCase<&str>) -> Option<&'static V> { if self.range.contains(&word.len()) { self.keys @@ -70,6 +71,7 @@ impl DictTable { } } + #[inline] pub fn iter(&self) -> impl Iterator, &'static V)> + '_ { (0..self.keys.len()).map(move |i| (self.keys[i].convert(), &self.values[i])) }