From 5b29113ec8b3e743b7a62154f8254955006e263d Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 6 Jul 2021 11:08:00 -0500 Subject: [PATCH] refactor(typos): Remove unused calculations In #293, we moved where we were filtering out results but never switched from `filter_map` to map`, so this does that. --- crates/typos/src/tokens.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/typos/src/tokens.rs b/crates/typos/src/tokens.rs index cdbaea5..107fe75 100644 --- a/crates/typos/src/tokens.rs +++ b/crates/typos/src/tokens.rs @@ -46,10 +46,7 @@ impl Tokenizer { } else { itertools::Either::Right(ascii_parser::iter_identifiers(content.as_bytes())) }; - iter.filter_map(move |identifier| { - let offset = offset(content.as_bytes(), identifier.as_bytes()); - self.transform(identifier, offset) - }) + iter.map(move |identifier| self.transform(identifier, content.as_bytes())) } pub fn parse_bytes<'c>(&'c self, content: &'c [u8]) -> impl Iterator> { @@ -60,17 +57,15 @@ impl Tokenizer { } else { itertools::Either::Right(ascii_parser::iter_identifiers(content)) }; - iter.filter_map(move |identifier| { - let offset = offset(content, identifier.as_bytes()); - self.transform(identifier, offset) - }) + iter.map(move |identifier| self.transform(identifier, content)) } - fn transform<'i>(&self, identifier: &'i str, offset: usize) -> Option> { + fn transform<'i>(&self, identifier: &'i str, content: &[u8]) -> Identifier<'i> { debug_assert!(!identifier.is_empty()); let case = Case::None; - Some(Identifier::new_unchecked(identifier, case, offset)) + let offset = offset(content, identifier.as_bytes()); + Identifier::new_unchecked(identifier, case, offset) } }