LibJS: Don't create unique FunctionParameters for every empty param set

This commit is contained in:
Andreas Kling 2025-11-08 13:58:15 +01:00 committed by Andreas Kling
parent 72aa90312a
commit d3e8fbd9cd
Notes: github-actions[bot] 2025-11-09 11:15:51 +00:00

View file

@ -3139,6 +3139,10 @@ NonnullRefPtr<FunctionParameters const> Parser::parse_formal_parameters(int& fun
if (!match(TokenType::Eof) && !match(TokenType::ParenClose))
expected(Token::name(TokenType::ParenClose));
// OPTIMIZATION: If there are no parameters, return the shared empty FunctionParameters instance.
if (parameters.is_empty())
return FunctionParameters::empty();
parameters.shrink_to_fit();
return FunctionParameters::create(move(parameters));
}