Skip to content

Commit b9aeaa3

Browse files
authored
perf(es/parser): Remove start in State (#11201)
**Description:** The only use of `start` is in the error span `read_digits`, so I think it can be removed.
1 parent eda01e5 commit b9aeaa3

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

.changeset/sweet-pumas-prove.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_parser: patch
4+
---
5+
6+
perf(es/parser): Remove `start` in `State`

crates/swc_ecma_parser/src/lexer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ impl<'a> Lexer<'a> {
12121212
}
12131213

12141214
fn read_int_u32<const RADIX: u8>(&mut self, len: u8) -> LexResult<Option<u32>> {
1215-
let start = self.state().start();
1215+
let start = self.cur_pos();
12161216

12171217
let mut count = 0;
12181218
let v = self.read_digits::<_, Option<u32>, RADIX>(

crates/swc_ecma_parser/src/lexer/state.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub struct State {
3434
/// TODO: Remove this field.
3535
is_first: bool,
3636
pub next_regexp: Option<BytePos>,
37-
pub start: BytePos,
3837
pub prev_hi: BytePos,
3938

4039
pub(super) token_value: Option<TokenValue>,
@@ -392,14 +391,6 @@ impl Lexer<'_> {
392391
return Ok(Token::Eof);
393392
}
394393

395-
// println!(
396-
// "\tContext: ({:?}) {:?}",
397-
// self.input.cur().unwrap(),
398-
// self.state.context.0
399-
// );
400-
401-
self.state.start = *start;
402-
403394
self.read_token()
404395
}
405396

@@ -499,8 +490,6 @@ impl Lexer<'_> {
499490
value: value.into(),
500491
});
501492

502-
self.state.start = start;
503-
504493
Ok(Token::JSXText)
505494
}
506495

@@ -587,7 +576,6 @@ impl State {
587576
had_line_break: false,
588577
is_first: true,
589578
next_regexp: None,
590-
start: BytePos(0),
591579
prev_hi: start_pos,
592580
token_value: None,
593581
token_type: None,
@@ -625,11 +613,6 @@ impl State {
625613
self.prev_hi
626614
}
627615

628-
#[inline(always)]
629-
pub fn start(&self) -> BytePos {
630-
self.start
631-
}
632-
633616
pub fn can_have_trailing_line_comment(&self) -> bool {
634617
let Some(t) = self.token_type() else {
635618
return true;

0 commit comments

Comments
 (0)