diff --git a/benches/tokenize.rs b/benches/tokenize.rs index f316581..75b1b9c 100644 --- a/benches/tokenize.rs +++ b/benches/tokenize.rs @@ -6,34 +6,34 @@ mod data; #[bench] fn symbol_parse_empty(b: &mut test::Bencher) { - b.iter(|| typos::tokens::Identifier::parse(data::EMPTY.as_bytes()).last()); + b.iter(|| typos::tokens::Identifier::parse_bytes(data::EMPTY.as_bytes()).last()); } #[bench] fn symbol_parse_no_tokens(b: &mut test::Bencher) { - b.iter(|| typos::tokens::Identifier::parse(data::NO_TOKENS.as_bytes()).last()); + b.iter(|| typos::tokens::Identifier::parse_bytes(data::NO_TOKENS.as_bytes()).last()); } #[bench] fn symbol_parse_single_token(b: &mut test::Bencher) { b.iter(|| { - typos::tokens::Identifier::parse(data::SINGLE_TOKEN.as_bytes()).last(); + typos::tokens::Identifier::parse_bytes(data::SINGLE_TOKEN.as_bytes()).last(); }); } #[bench] fn symbol_parse_sherlock(b: &mut test::Bencher) { - b.iter(|| typos::tokens::Identifier::parse(data::SHERLOCK.as_bytes()).last()); + b.iter(|| typos::tokens::Identifier::parse_bytes(data::SHERLOCK.as_bytes()).last()); } #[bench] fn symbol_parse_code(b: &mut test::Bencher) { - b.iter(|| typos::tokens::Identifier::parse(data::CODE.as_bytes()).last()); + b.iter(|| typos::tokens::Identifier::parse_bytes(data::CODE.as_bytes()).last()); } #[bench] fn symbol_parse_corpus(b: &mut test::Bencher) { - b.iter(|| typos::tokens::Identifier::parse(data::CORPUS.as_bytes()).last()); + b.iter(|| typos::tokens::Identifier::parse_bytes(data::CORPUS.as_bytes()).last()); } #[bench] diff --git a/src/lib.rs b/src/lib.rs index facb8bf..f2d9b99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,7 @@ pub fn process_file( for (line_idx, line) in buffer.lines().enumerate() { let line_num = line_idx + 1; - for ident in tokens::Identifier::parse(line) { + for ident in tokens::Identifier::parse_bytes(line) { if !ignore_hex && is_hex(ident.token()) { continue; } diff --git a/src/tokens.rs b/src/tokens.rs index 9d3727a..1543385 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -14,7 +14,7 @@ pub struct Identifier<'t> { impl<'t> Identifier<'t> { pub fn new(token: &'t str, offset: usize) -> Result { - let mut itr = Self::parse(token.as_bytes()); + let mut itr = Self::parse_bytes(token.as_bytes()); let mut item = itr .next() .ok_or_else(|| failure::format_err!("Invalid ident (none found): {:?}", token))?; @@ -38,7 +38,7 @@ impl<'t> Identifier<'t> { Self { token, offset } } - pub fn parse(content: &[u8]) -> impl Iterator> { + pub fn parse_bytes(content: &[u8]) -> impl Iterator> { lazy_static::lazy_static! { // Getting false positives for this lint #[allow(clippy::invalid_regex)] @@ -242,7 +242,7 @@ mod test { fn tokenize_empty_is_empty() { let input = b""; let expected: Vec = vec![]; - let actual: Vec<_> = Identifier::parse(input).collect(); + let actual: Vec<_> = Identifier::parse_bytes(input).collect(); assert_eq!(expected, actual); } @@ -250,7 +250,7 @@ mod test { fn tokenize_word_is_word() { let input = b"word"; let expected: Vec = vec![Identifier::new_unchecked("word", 0)]; - let actual: Vec<_> = Identifier::parse(input).collect(); + let actual: Vec<_> = Identifier::parse_bytes(input).collect(); assert_eq!(expected, actual); } @@ -261,7 +261,7 @@ mod test { Identifier::new_unchecked("A", 0), Identifier::new_unchecked("B", 2), ]; - let actual: Vec<_> = Identifier::parse(input).collect(); + let actual: Vec<_> = Identifier::parse_bytes(input).collect(); assert_eq!(expected, actual); } @@ -272,7 +272,7 @@ mod test { Identifier::new_unchecked("A", 0), Identifier::new_unchecked("B", 2), ]; - let actual: Vec<_> = Identifier::parse(input).collect(); + let actual: Vec<_> = Identifier::parse_bytes(input).collect(); assert_eq!(expected, actual); } @@ -283,7 +283,7 @@ mod test { Identifier::new_unchecked("A", 0), Identifier::new_unchecked("B", 3), ]; - let actual: Vec<_> = Identifier::parse(input).collect(); + let actual: Vec<_> = Identifier::parse_bytes(input).collect(); assert_eq!(expected, actual); } @@ -291,7 +291,7 @@ mod test { fn tokenize_underscore_doesnt_separate() { let input = b"A_B"; let expected: Vec = vec![Identifier::new_unchecked("A_B", 0)]; - let actual: Vec<_> = Identifier::parse(input).collect(); + let actual: Vec<_> = Identifier::parse_bytes(input).collect(); assert_eq!(expected, actual); }