Skip to content

Commit

Permalink
perf(parser): make not at EOF the hot path in Source methods
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jul 31, 2024
1 parent aa2cd33 commit 96baf9e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/oxc_parser/src/lexer/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,11 @@ impl<'a> Source<'a> {
#[allow(dead_code)]
#[inline]
unsafe fn next_byte(&mut self) -> Option<u8> {
if self.is_eof() {
None
} else {
if !self.is_eof() {
// SAFETY: Safe to read from `ptr` as we just checked it's not out of bounds
Some(self.next_byte_unchecked())
} else {
None
}
}

Expand Down Expand Up @@ -503,11 +503,11 @@ impl<'a> Source<'a> {
/// Peek next byte of source without consuming it.
#[inline]
pub(super) fn peek_byte(&self) -> Option<u8> {
if self.is_eof() {
None
} else {
if !self.is_eof() {
// SAFETY: Safe to read from `ptr` as we just checked it's not out of bounds
Some(unsafe { self.peek_byte_unchecked() })
} else {
None
}
}

Expand Down

0 comments on commit 96baf9e

Please sign in to comment.