mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 21:45:20 +00:00
LibJS: Add a fast failure path to try_parse_arrow_function_expression()
The save/load of parser state performed by lookahead parsing is quite expensive so let's try to avoid it in the most common case. This is a 15-20% speedup on various chunks of JS I've tested. :^)
This commit is contained in:
parent
a50e33abe3
commit
910de95e7a
Notes:
sideshowbarker
2024-07-18 03:58:45 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/910de95e7aa
1 changed files with 14 additions and 0 deletions
|
@ -449,6 +449,20 @@ static bool is_simple_parameter_list(Vector<FunctionNode::Parameter> const& para
|
|||
|
||||
RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expect_parens)
|
||||
{
|
||||
if (!expect_parens) {
|
||||
// NOTE: This is a fast path where we try to fail early in case this can't possibly
|
||||
// be a match. The idea is to avoid the expensive parser state save/load mechanism.
|
||||
// The logic is duplicated below in the "real" !expect_parens branch.
|
||||
if (!match_identifier() && !match(TokenType::Yield) && !match(TokenType::Await))
|
||||
return nullptr;
|
||||
auto forked_lexer = m_state.lexer;
|
||||
auto token = forked_lexer.next();
|
||||
if (token.trivia_contains_line_terminator())
|
||||
return nullptr;
|
||||
if (token.type() != TokenType::Arrow)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
save_state();
|
||||
auto rule_start = push_start();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue