Skip to content

Commit 1be2ca0

Browse files
authored
perf(es/parser): Optimize next_token (#10654)
1 parent 9262a59 commit 1be2ca0

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

.changeset/four-camels-sneeze.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
swc_ecma_lexer: patch
4+
---
5+
6+
less compute in next token

crates/swc_common/src/input.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl<'a> StringInput<'a> {
5656
self.orig_start
5757
}
5858

59+
#[inline(always)]
5960
pub fn end_pos(&self) -> BytePos {
6061
self.orig_end
6162
}

crates/swc_ecma_lexer/src/lexer/state.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -759,15 +759,11 @@ impl Lexer<'_> {
759759
*start = self.input.cur_pos();
760760
};
761761

762-
match self.input.cur() {
763-
Some(..) => {}
762+
if self.input.last_pos() == self.input.end_pos() {
764763
// End of input.
765-
None => {
766-
self.consume_pending_comments();
767-
768-
return Ok(None);
769-
}
770-
};
764+
self.consume_pending_comments();
765+
return Ok(None);
766+
}
771767

772768
// println!(
773769
// "\tContext: ({:?}) {:?}",

crates/swc_ecma_parser/src/lexer/state.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,11 @@ impl Lexer<'_> {
378378
self.skip_space::<true>();
379379
*start = self.input.cur_pos();
380380

381-
match self.input.cur() {
382-
Some(..) => {}
381+
if self.input.last_pos() == self.input.end_pos() {
383382
// End of input.
384-
None => {
385-
self.consume_pending_comments();
386-
387-
return Ok(None);
388-
}
389-
};
383+
self.consume_pending_comments();
384+
return Ok(None);
385+
}
390386

391387
// println!(
392388
// "\tContext: ({:?}) {:?}",

0 commit comments

Comments
 (0)