Skip to content

Commit

Permalink
avoid double-parse of utf8 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Easyoakland committed Jun 23, 2024
1 parent c1360d6 commit 25a3cec
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ impl<'a> Tokens for StrTokens<'a> {

fn next(&mut self) -> Option<Self::Item> {
// Cursor should always start at a valid char boundary so this will never panic.
let next_char = self.str[self.cursor..].chars().next()?;
self.cursor += next_char.len_utf8();
let str = &self.str[self.cursor..];
let mut chars = str.chars();
let next_char = chars.next()?;
self.cursor += str.len() - chars.as_str().len();
Some(next_char)
}

Expand Down

0 comments on commit 25a3cec

Please sign in to comment.