Skip to content

Commit

Permalink
Optimize text lexer with predictive parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbabcock committed Dec 21, 2023
1 parent 59f3159 commit c7c59a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/text/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<'de, 'a, R: Read, E: Encoding> de::MapAccess<'de> for TextReaderMap<'a, R,
V: DeserializeSeed<'de>,
{
let de = unsafe { &mut *(self.de as *mut _) };
let token = self.de.reader.read()?;
let token = self.de.reader.read_expect_equals()?;
let deser = if let Token::Operator(op) = token {
let new_token = self.de.reader.read()?;
let mut deser = TextReaderTokenDeserializer::new(de, new_token);
Expand Down
11 changes: 11 additions & 0 deletions src/text/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,17 @@ where
}
}

#[inline]
pub(crate) fn read_expect_equals(&mut self) -> Result<Token, ReaderError> {
match self.buf.window().first() {
Some(b'=') => {
self.buf.advance(1);
Ok(Token::Operator(Operator::Equal))
}
_ => self.read(),
}
}

/// Read a token, returning none when all the data has been consumed
///
/// ```rust
Expand Down

0 comments on commit c7c59a4

Please sign in to comment.