1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:27:45 +00:00

LibJS: Use const references to avoid some copies in the parser

This commit is contained in:
Linus Groh 2021-02-24 09:58:24 +01:00 committed by Andreas Kling
parent 692bfc6ba2
commit 7dd233b2b6
2 changed files with 6 additions and 6 deletions

View file

@ -886,7 +886,7 @@ NonnullRefPtr<ArrayExpression> Parser::parse_array_expression()
return create_ast_node<ArrayExpression>({ rule_start.position(), position() }, move(elements));
}
NonnullRefPtr<StringLiteral> Parser::parse_string_literal(Token token, bool in_template_literal)
NonnullRefPtr<StringLiteral> Parser::parse_string_literal(const Token& token, bool in_template_literal)
{
auto rule_start = push_start();
auto status = Token::StringValueStatus::Ok;
@ -974,7 +974,7 @@ NonnullRefPtr<TemplateLiteral> Parser::parse_template_literal(bool is_tagged)
return create_ast_node<TemplateLiteral>({ rule_start.position(), position() }, expressions);
}
NonnullRefPtr<Expression> Parser::parse_expression(int min_precedence, Associativity associativity, Vector<TokenType> forbidden)
NonnullRefPtr<Expression> Parser::parse_expression(int min_precedence, Associativity associativity, const Vector<TokenType>& forbidden)
{
auto rule_start = push_start();
auto expression = parse_primary_expression();
@ -1844,7 +1844,7 @@ bool Parser::match_unary_prefixed_expression() const
|| type == TokenType::Delete;
}
bool Parser::match_secondary_expression(Vector<TokenType> forbidden) const
bool Parser::match_secondary_expression(const Vector<TokenType>& forbidden) const
{
auto type = m_parser_state.m_current_token.type();
if (forbidden.contains_slow(type))

View file

@ -83,13 +83,13 @@ public:
NonnullRefPtr<WithStatement> parse_with_statement();
NonnullRefPtr<DebuggerStatement> parse_debugger_statement();
NonnullRefPtr<ConditionalExpression> parse_conditional_expression(NonnullRefPtr<Expression> test);
NonnullRefPtr<Expression> parse_expression(int min_precedence, Associativity associate = Associativity::Right, Vector<TokenType> forbidden = {});
NonnullRefPtr<Expression> parse_expression(int min_precedence, Associativity associate = Associativity::Right, const Vector<TokenType>& forbidden = {});
NonnullRefPtr<Expression> parse_primary_expression();
NonnullRefPtr<Expression> parse_unary_prefixed_expression();
NonnullRefPtr<RegExpLiteral> parse_regexp_literal();
NonnullRefPtr<ObjectExpression> parse_object_expression();
NonnullRefPtr<ArrayExpression> parse_array_expression();
NonnullRefPtr<StringLiteral> parse_string_literal(Token token, bool in_template_literal = false);
NonnullRefPtr<StringLiteral> parse_string_literal(const Token& token, bool in_template_literal = false);
NonnullRefPtr<TemplateLiteral> parse_template_literal(bool is_tagged);
NonnullRefPtr<Expression> parse_secondary_expression(NonnullRefPtr<Expression>, int min_precedence, Associativity associate = Associativity::Right);
NonnullRefPtr<CallExpression> parse_call_expression(NonnullRefPtr<Expression>);
@ -153,7 +153,7 @@ private:
Associativity operator_associativity(TokenType) const;
bool match_expression() const;
bool match_unary_prefixed_expression() const;
bool match_secondary_expression(Vector<TokenType> forbidden = {}) const;
bool match_secondary_expression(const Vector<TokenType>& forbidden = {}) const;
bool match_statement() const;
bool match_declaration() const;
bool match_variable_declaration() const;