forked from oxc-project/oxc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(parser): eat whitespace after line break (oxc-project#2353)
Uses the `byte_search!` macro introduced in oxc-project#2352 to consume whitespace after a line break.
- Loading branch information
1 parent
d3a59f2
commit 8376f15
Showing
3 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use super::{ | ||
search::{byte_search, safe_byte_match_table, SafeByteMatchTable}, | ||
Kind, Lexer, | ||
}; | ||
|
||
static NOT_REGULAR_WHITESPACE_OR_LINE_BREAK_TABLE: SafeByteMatchTable = | ||
safe_byte_match_table!(|b| !matches!(b, b' ' | b'\t' | b'\r' | b'\n')); | ||
|
||
impl<'a> Lexer<'a> { | ||
pub(super) fn line_break_handler(&mut self) -> Kind { | ||
self.token.is_on_new_line = true; | ||
|
||
// Indentation is common after a line break. | ||
// Consume it, along with any further line breaks. | ||
// Irregular line breaks and whitespace are not consumed. | ||
// They're uncommon, so leave them for the next call to `handle_byte` to take care of. | ||
byte_search! { | ||
lexer: self, | ||
table: NOT_REGULAR_WHITESPACE_OR_LINE_BREAK_TABLE, | ||
handle_match: |_next_byte, _start| { | ||
Kind::Skip | ||
}, | ||
handle_eof: |_start| { | ||
Kind::Skip | ||
}, | ||
}; | ||
} | ||
} |