Skip to content

Commit 8084066

Browse files
authored
perf: Optimize Input::reset_to (#10719)
1 parent 1ae2d3f commit 8084066

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

.changeset/old-squids-greet.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_common: patch
3+
swc_core: patch
4+
---
5+
6+
refactor(es/lexer): unnecessary reset input

crates/swc_common/src/input.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ impl<'a> Input<'a> for StringInput<'a> {
180180

181181
#[inline]
182182
unsafe fn reset_to(&mut self, to: BytePos) {
183+
if self.last_pos == to {
184+
// No need to reset.
185+
return;
186+
}
187+
183188
let orig = self.orig;
184189
let idx = (to - self.orig_start).0 as usize;
185190

crates/swc_ecma_parser/src/parser/class_and_fn.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
#[cfg(test)]
2-
#[allow(unused)]
32
mod tests {
43

54
use swc_common::DUMMY_SP as span;
65
use swc_ecma_ast::*;
7-
use swc_ecma_lexer::{common::parser::expr::parse_lhs_expr, Syntax};
6+
use swc_ecma_lexer::Syntax;
87
use swc_ecma_visit::assert_eq_ignore_span;
98

10-
use super::*;
119
use crate::test_parser;
1210

13-
fn lhs(s: &'static str) -> Box<Expr> {
14-
test_parser(s, Syntax::default(), |p| parse_lhs_expr::<_, false>(p))
15-
}
16-
1711
fn expr(s: &'static str) -> Box<Expr> {
1812
test_parser(s, Syntax::default(), |p| p.parse_expr())
1913
}

0 commit comments

Comments
 (0)