mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
perf(parser): a few micro optimizations
This commit is contained in:
parent
0bbbc7768f
commit
cf278a2760
5 changed files with 8 additions and 7 deletions
|
|
@ -16,6 +16,7 @@ impl<'a> AstBuilder<'a> {
|
|||
Self { allocator }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn alloc<T>(&self, value: T) -> Box<'a, T> {
|
||||
Box(self.allocator.alloc(value))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -458,8 +458,8 @@ impl<'a> Parser<'a> {
|
|||
in_optional_chain: &mut bool,
|
||||
) -> Result<Expression<'a>> {
|
||||
let node = self.start_node();
|
||||
let lhs = self.parse_primary_expression()?;
|
||||
self.parse_member_expression_rhs(node, lhs, in_optional_chain)
|
||||
self.parse_primary_expression()
|
||||
.and_then(|lhs| self.parse_member_expression_rhs(node, lhs, in_optional_chain))
|
||||
}
|
||||
|
||||
/// Section 13.3 Super Call
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
let return_type = self.parse_ts_return_type_annotation()?;
|
||||
|
||||
let body = self.at(Kind::LCurly).then(|| self.parse_function_body()).transpose()?;
|
||||
let body = if self.at(Kind::LCurly) { Some(self.parse_function_body()?) } else { None };
|
||||
|
||||
self.ctx = self.ctx.and_await(has_await).and_yield(has_yield);
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ impl<'a> Lexer<'a> {
|
|||
source_type,
|
||||
current,
|
||||
errors,
|
||||
lookahead: VecDeque::new(),
|
||||
lookahead: VecDeque::with_capacity(4),
|
||||
context: LexerContext::Regular,
|
||||
}
|
||||
}
|
||||
|
|
@ -499,7 +499,7 @@ impl<'a> Lexer<'a> {
|
|||
fn skip_multi_line_comment(&mut self) -> Kind {
|
||||
let remaining = self.remaining().as_bytes();
|
||||
let newline = self.current.token.is_on_new_line;
|
||||
let state = SkipMultilineComment::new(newline, remaining).simd(remaining);
|
||||
let state = SkipMultilineComment::new(newline, remaining).simd();
|
||||
|
||||
// SAFETY: offset is computed to the boundary
|
||||
self.current.chars =
|
||||
|
|
|
|||
|
|
@ -119,8 +119,8 @@ impl<'a> SkipMultilineComment<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn simd(mut self, remaining: &[u8]) -> Self {
|
||||
let (chunks, remainder) = remaining.as_chunks::<ELEMENTS>();
|
||||
pub fn simd(mut self) -> Self {
|
||||
let (chunks, remainder) = self.remaining.as_chunks::<ELEMENTS>();
|
||||
|
||||
for chunk in chunks {
|
||||
self.check(chunk, chunk.len());
|
||||
|
|
|
|||
Loading…
Reference in a new issue