diff --git a/src/dict.rs b/src/dict.rs index f3178e5..443a616 100644 --- a/src/dict.rs +++ b/src/dict.rs @@ -168,7 +168,7 @@ impl<'i, 'w, D: typos::Dictionary> Override<'i, 'w, D> { .collect(); } - pub fn interpret<'z, I: Iterator>( + fn interpret<'z, I: Iterator>( cases: I, ) -> impl Iterator)> { cases.map(|(typo, correction)| { @@ -186,19 +186,29 @@ impl<'i, 'w, D: typos::Dictionary> Override<'i, 'w, D> { impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> { fn correct_ident<'s, 't>(&'s self, ident: typos::tokens::Identifier<'t>) -> Option> { - self.identifiers - .get(ident.token()) - .map(|c| c.borrow()) - .or_else(|| self.inner.correct_ident(ident)) + // Skip hashing if we can + if !self.identifiers.is_empty() { + self.identifiers + .get(ident.token()) + .map(|c| c.borrow()) + .or_else(|| self.inner.correct_ident(ident)) + } else { + None + } } fn correct_word<'s, 't>(&'s self, word: typos::tokens::Word<'t>) -> Option> { - let w = UniCase::new(word.token()); - // HACK: couldn't figure out the lifetime issue with replacing `cloned` with `borrow` - self.words - .get(&w) - .cloned() - .or_else(|| self.inner.correct_word(word)) + // Skip hashing if we can + if !self.words.is_empty() { + let w = UniCase::new(word.token()); + // HACK: couldn't figure out the lifetime issue with replacing `cloned` with `borrow` + self.words + .get(&w) + .cloned() + .or_else(|| self.inner.correct_word(word)) + } else { + None + } } }