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:
parent
8bde4e94d8
commit
33f038ba7a
1 changed files with 8 additions and 0 deletions
|
@ -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 = [&] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue