瀏覽代碼

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

Linus Groh 4 年之前
父節點
當前提交
7dd233b2b6
共有 2 個文件被更改,包括 6 次插入6 次删除
  1. 3 3
      Userland/Libraries/LibJS/Parser.cpp
  2. 3 3
      Userland/Libraries/LibJS/Parser.h

+ 3 - 3
Userland/Libraries/LibJS/Parser.cpp

@@ -886,7 +886,7 @@ NonnullRefPtr<ArrayExpression> Parser::parse_array_expression()
     return create_ast_node<ArrayExpression>({ rule_start.position(), position() }, move(elements));
     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 rule_start = push_start();
     auto status = Token::StringValueStatus::Ok;
     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);
     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 rule_start = push_start();
     auto expression = parse_primary_expression();
     auto expression = parse_primary_expression();
@@ -1844,7 +1844,7 @@ bool Parser::match_unary_prefixed_expression() const
         || type == TokenType::Delete;
         || 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();
     auto type = m_parser_state.m_current_token.type();
     if (forbidden.contains_slow(type))
     if (forbidden.contains_slow(type))

+ 3 - 3
Userland/Libraries/LibJS/Parser.h

@@ -83,13 +83,13 @@ public:
     NonnullRefPtr<WithStatement> parse_with_statement();
     NonnullRefPtr<WithStatement> parse_with_statement();
     NonnullRefPtr<DebuggerStatement> parse_debugger_statement();
     NonnullRefPtr<DebuggerStatement> parse_debugger_statement();
     NonnullRefPtr<ConditionalExpression> parse_conditional_expression(NonnullRefPtr<Expression> test);
     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_primary_expression();
     NonnullRefPtr<Expression> parse_unary_prefixed_expression();
     NonnullRefPtr<Expression> parse_unary_prefixed_expression();
     NonnullRefPtr<RegExpLiteral> parse_regexp_literal();
     NonnullRefPtr<RegExpLiteral> parse_regexp_literal();
     NonnullRefPtr<ObjectExpression> parse_object_expression();
     NonnullRefPtr<ObjectExpression> parse_object_expression();
     NonnullRefPtr<ArrayExpression> parse_array_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<TemplateLiteral> parse_template_literal(bool is_tagged);
     NonnullRefPtr<Expression> parse_secondary_expression(NonnullRefPtr<Expression>, int min_precedence, Associativity associate = Associativity::Right);
     NonnullRefPtr<Expression> parse_secondary_expression(NonnullRefPtr<Expression>, int min_precedence, Associativity associate = Associativity::Right);
     NonnullRefPtr<CallExpression> parse_call_expression(NonnullRefPtr<Expression>);
     NonnullRefPtr<CallExpression> parse_call_expression(NonnullRefPtr<Expression>);
@@ -153,7 +153,7 @@ private:
     Associativity operator_associativity(TokenType) const;
     Associativity operator_associativity(TokenType) const;
     bool match_expression() const;
     bool match_expression() const;
     bool match_unary_prefixed_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_statement() const;
     bool match_declaration() const;
     bool match_declaration() const;
     bool match_variable_declaration() const;
     bool match_variable_declaration() const;