perf(parser): use memchr for lexing comments (#8193)
This commit is contained in:
@@ -407,7 +407,9 @@ impl<'source> Lexer<'source> {
|
||||
#[cfg(debug_assertions)]
|
||||
debug_assert_eq!(self.cursor.previous(), '#');
|
||||
|
||||
self.cursor.eat_while(|c| !matches!(c, '\n' | '\r'));
|
||||
let bytes = self.cursor.rest().as_bytes();
|
||||
let offset = memchr::memchr2(b'\n', b'\r', bytes).unwrap_or(bytes.len());
|
||||
self.cursor.skip_bytes(offset);
|
||||
|
||||
Tok::Comment(self.token_text().to_string())
|
||||
}
|
||||
|
||||
@@ -127,4 +127,21 @@ impl<'a> Cursor<'a> {
|
||||
self.bump();
|
||||
}
|
||||
}
|
||||
|
||||
/// Skips the next `count` bytes.
|
||||
///
|
||||
/// ## Panics
|
||||
/// - If `count` is larger than the remaining bytes in the input stream.
|
||||
/// - If `count` indexes into a multi-byte character.
|
||||
pub(super) fn skip_bytes(&mut self, count: usize) {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
self.prev_char = self.chars.as_str()[..count]
|
||||
.chars()
|
||||
.next_back()
|
||||
.unwrap_or('\0');
|
||||
}
|
||||
|
||||
self.chars = self.chars.as_str()[count..].chars();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user