From 04a5d6dca7c3e90031e06ba67296ce7ac55e1202 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 20 Apr 2021 16:25:32 -0700 Subject: [PATCH] Avoid performing copies of `ExpectedNode` objects. These contain `vector`s, resulting in deep copies of potentially large trees. --- parser/parse_test_helpers.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/parser/parse_test_helpers.h b/parser/parse_test_helpers.h index 6be527c51f82..f9ec25a4ecd1 100644 --- a/parser/parse_test_helpers.h +++ b/parser/parse_test_helpers.h @@ -310,30 +310,31 @@ auto MatchNode(Args... args) -> ExpectedNode { // MatchParameterList(MatchParameterListEnd()), // MatchDeclarationEnd(";")), // MatchFileEnd()}); -#define CARBON_PARSE_NODE_KIND(kind) \ - template \ - auto Match##kind(Args... args)->ExpectedNode { \ - return MatchNode(ParseNodeKind::kind(), args...); \ +#define CARBON_PARSE_NODE_KIND(kind) \ + template \ + auto Match##kind(Args... args)->ExpectedNode { \ + return MatchNode(ParseNodeKind::kind(), std::move(args)...); \ } #include "parse_node_kind.def" // Helper for matching a designator `lhs.rhs`. auto MatchDesignator(ExpectedNode lhs, std::string rhs) -> ExpectedNode { - return MatchDesignatorExpression(lhs, MatchDesignatedName(rhs)); + return MatchDesignatorExpression(std::move(lhs), MatchDesignatedName(rhs)); } // Helper for matching a function parameter list. template auto MatchParameters(Args... args) -> ExpectedNode { - return MatchParameterList("(", args..., MatchParameterListEnd()); + return MatchParameterList("(", std::move(args)..., MatchParameterListEnd()); } // Helper for matching the statements in the body of a simple function // definition with no parameters. template auto MatchFunctionWithBody(Args... args) -> ExpectedNode { - return MatchFunctionDeclaration(MatchDeclaredName(), MatchParameters(), - MatchCodeBlock(args..., MatchCodeBlockEnd())); + return MatchFunctionDeclaration( + MatchDeclaredName(), MatchParameters(), + MatchCodeBlock(std::move(args)..., MatchCodeBlockEnd())); } } // namespace NodeMatchers