Skip to content

Commit 145fba4

Browse files
bvanjoikdy1
authored andcommitted
perf(es/lexer): Reduce memory move (#10906)
1 parent 92ca5ec commit 145fba4

File tree

1 file changed

+13
-2
lines changed
  • crates/swc_ecma_parser/src/parser

1 file changed

+13
-2
lines changed

crates/swc_ecma_parser/src/parser/input.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,46 +175,57 @@ impl<'a, I: Tokens> swc_ecma_lexer::common::parser::buffer::Buffer<'a> for Buffe
175175
}
176176
}
177177

178+
#[inline(always)]
178179
fn set_cur(&mut self, token: TokenAndSpan) {
179180
self.cur = token
180181
}
181182

183+
#[inline(always)]
182184
fn next(&self) -> Option<&Self::Next> {
183185
self.next.as_ref()
184186
}
185187

188+
#[inline(always)]
186189
fn set_next(&mut self, token: Option<Self::Next>) {
187190
self.next = token;
188191
}
189192

193+
#[inline(always)]
190194
fn next_mut(&mut self) -> &mut Option<Self::Next> {
191195
&mut self.next
192196
}
193197

198+
#[inline(always)]
194199
fn cur(&self) -> &super::super::lexer::Token {
195200
&self.cur.token
196201
}
197202

203+
#[inline(always)]
198204
fn get_cur(&self) -> &TokenAndSpan {
199205
&self.cur
200206
}
201207

208+
#[inline(always)]
202209
fn get_cur_mut(&mut self) -> &mut TokenAndSpan {
203210
&mut self.cur
204211
}
205212

213+
#[inline(always)]
206214
fn prev_span(&self) -> Span {
207215
self.prev_span
208216
}
209217

218+
#[inline(always)]
210219
fn set_prev_span(&mut self, span: Span) {
211220
self.prev_span = span;
212221
}
213222

223+
#[inline(always)]
214224
fn iter(&self) -> &I {
215225
&self.iter
216226
}
217227

228+
#[inline(always)]
218229
fn iter_mut(&mut self) -> &mut I {
219230
&mut self.iter
220231
}
@@ -250,8 +261,8 @@ impl<'a, I: Tokens> swc_ecma_lexer::common::parser::buffer::Buffer<'a> for Buffe
250261
} else {
251262
TokenAndSpan::new(Token::Eof, self.prev_span(), true)
252263
};
253-
let prev = std::mem::replace(&mut self.cur, next);
254-
self.set_prev_span(prev.span());
264+
self.set_prev_span(self.cur.span());
265+
self.set_cur(next);
255266
}
256267

257268
fn expect_word_token_and_bump(&mut self) -> Atom {

0 commit comments

Comments
 (0)