mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 16:01:04 +01:00
Avoid performing copies of ExpectedNode objects.
These contain `vector<ExpectedNode>`s, resulting in deep copies of potentially large trees.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user