mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +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:
@@ -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 = [&] {
|
||||
|
||||
Reference in New Issue
Block a user