Skip to content

Commit

Permalink
feat: use peek()
Browse files Browse the repository at this point in the history
  • Loading branch information
indietyp committed Mar 31, 2023
1 parent 8aa9f7a commit ce1f038
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,6 @@ impl<'a, const GUARANTEED_UTF8: bool> Tokenizer<'a, GUARANTEED_UTF8> {
Ok(())
}

#[inline]
fn peek_char(&mut self) -> Result<&u8, Error> {
self.source.skip_ws();
let offset = self.source.offset;

self.source.peek().ok_or(Error {
offset,
kind: ErrorKind::UnexpectedEof,
})
}

#[inline]
pub fn peek(&mut self) -> Option<PeekableTokenKind> {
self.source.skip_ws();
Expand Down Expand Up @@ -801,11 +790,9 @@ impl<'a, const GUARANTEED_UTF8: bool> Parser<'a, GUARANTEED_UTF8> {
loop {
let offset = self.tokenizer.offset();

let token = self.tokenizer.peek_char().map_err(Error::into_fallable)?;

// a bit of a cheat for the sake of ultimate performance, instead of using an Option<Token>
// we look at the char itself to determine the of a token
if *token == b']' {
if self.tokenizer.peek() == Some(PeekableTokenKind::ArrayEnd) {
// commit the token
self.tokenizer.source.offset += 1;

Expand Down

0 comments on commit ce1f038

Please sign in to comment.