Avoid performing copies of ExpectedNode objects.

These contain `vector<ExpectedNode>`s, resulting in deep copies of
potentially large trees.
This commit is contained in:
Richard Smith
2021-04-20 23:43:25 -07:00
parent c0e83206be
commit 04a5d6dca7
+9 -8
View File
@@ -310,30 +310,31 @@ auto MatchNode(Args... args) -> ExpectedNode {
// MatchParameterList(MatchParameterListEnd()),
// MatchDeclarationEnd(";")),
// MatchFileEnd()});
#define CARBON_PARSE_NODE_KIND(kind) \
template <typename... Args> \
auto Match##kind(Args... args)->ExpectedNode { \
return MatchNode(ParseNodeKind::kind(), args...); \
#define CARBON_PARSE_NODE_KIND(kind) \
template <typename... Args> \
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 <typename... Args>
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 <typename... Args>
auto MatchFunctionWithBody(Args... args) -> ExpectedNode {
return MatchFunctionDeclaration(MatchDeclaredName(), MatchParameters(),
MatchCodeBlock(args..., MatchCodeBlockEnd()));
return MatchFunctionDeclaration(
MatchDeclaredName(), MatchParameters(),
MatchCodeBlock(std::move(args)..., MatchCodeBlockEnd()));
}
} // namespace NodeMatchers