mirror of
https://github.com/crate-ci/typos.git
synced 2025-01-11 09:11:39 -05:00
perf(dictgen): Make lookups faster for map/table
This commit is contained in:
parent
db16cb53c5
commit
083871447d
2 changed files with 4 additions and 0 deletions
|
@ -58,6 +58,7 @@ pub struct DictMap<V: 'static> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V> DictMap<V> {
|
impl<V> DictMap<V> {
|
||||||
|
#[inline]
|
||||||
pub fn find(&self, word: &'_ unicase::UniCase<&str>) -> Option<&V> {
|
pub fn find(&self, word: &'_ unicase::UniCase<&str>) -> Option<&V> {
|
||||||
if self.range.contains(&word.len()) {
|
if self.range.contains(&word.len()) {
|
||||||
self.map.get(&(*word).into())
|
self.map.get(&(*word).into())
|
||||||
|
@ -66,6 +67,7 @@ impl<V> DictMap<V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn iter(&self) -> impl Iterator<Item = (unicase::UniCase<&str>, &V)> + '_ {
|
pub fn iter(&self) -> impl Iterator<Item = (unicase::UniCase<&str>, &V)> + '_ {
|
||||||
self.map.entries().map(|(k, v)| (k.convert(), v))
|
self.map.entries().map(|(k, v)| (k.convert(), v))
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ pub struct DictTable<V: 'static> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V> DictTable<V> {
|
impl<V> DictTable<V> {
|
||||||
|
#[inline]
|
||||||
pub fn find(&self, word: &'_ unicase::UniCase<&str>) -> Option<&'static V> {
|
pub fn find(&self, word: &'_ unicase::UniCase<&str>) -> Option<&'static V> {
|
||||||
if self.range.contains(&word.len()) {
|
if self.range.contains(&word.len()) {
|
||||||
self.keys
|
self.keys
|
||||||
|
@ -70,6 +71,7 @@ impl<V> DictTable<V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn iter(&self) -> impl Iterator<Item = (unicase::UniCase<&'static str>, &'static V)> + '_ {
|
pub fn iter(&self) -> impl Iterator<Item = (unicase::UniCase<&'static str>, &'static V)> + '_ {
|
||||||
(0..self.keys.len()).map(move |i| (self.keys[i].convert(), &self.values[i]))
|
(0..self.keys.len()).map(move |i| (self.keys[i].convert(), &self.values[i]))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue