1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:37:46 +00:00

LibJS: Add fast failure path to try_parse_labelled_statement()

If the next token isn't a TokenType::Colon (:), this can't possibly be a
labelled statement, so we can fail before having to save_state().

This improves parsing time on a large chunk of JS by ~12.5%.
This commit is contained in:
Andreas Kling 2021-09-18 19:39:20 +02:00
parent 8bde4e94d8
commit 33f038ba7a

View file

@ -566,6 +566,14 @@ RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expe
RefPtr<Statement> Parser::try_parse_labelled_statement(AllowLabelledFunction allow_function)
{
{
// NOTE: This is a fast path where we try to fail early to avoid the expensive save_state+load_state.
auto forked_lexer = m_state.lexer;
auto token = forked_lexer.next();
if (token.type() != TokenType::Colon)
return {};
}
save_state();
auto rule_start = push_start();
ArmedScopeGuard state_rollback_guard = [&] {