[clang] 3e9a7b2 - [ASTMatchers] Matcher macros with params move params instead of copying

Nathan James via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 24 23:50:41 PST 2020


Author: Nathan James
Date: 2020-02-25T07:50:34Z
New Revision: 3e9a7b2ba470bbe9cf3de3e4b15ba09dcfd206aa

URL: https://github.com/llvm/llvm-project/commit/3e9a7b2ba470bbe9cf3de3e4b15ba09dcfd206aa
DIFF: https://github.com/llvm/llvm-project/commit/3e9a7b2ba470bbe9cf3de3e4b15ba09dcfd206aa.diff

LOG: [ASTMatchers] Matcher macros with params move params instead of copying

Summary: Use move semantics instead of copying for AST Matchers with parameters

Reviewers: aaron.ballman, gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75096

Added: 
    

Modified: 
    clang/include/clang/ASTMatchers/ASTMatchersMacros.h

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/ASTMatchers/ASTMatchersMacros.h b/clang/include/clang/ASTMatchers/ASTMatchersMacros.h
index 1d96ba6231cf..4977bf32e9f6 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersMacros.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersMacros.h
@@ -134,9 +134,8 @@
   class matcher_##DefineMatcher##OverloadId##Matcher                           \
       : public ::clang::ast_matchers::internal::MatcherInterface<Type> {       \
   public:                                                                      \
-    explicit matcher_##DefineMatcher##OverloadId##Matcher(                     \
-        ParamType const &A##Param)                                             \
-        : Param(A##Param) {}                                                   \
+    explicit matcher_##DefineMatcher##OverloadId##Matcher(ParamType A##Param)  \
+        : Param(std::move(A##Param)) {}                                        \
     bool matches(const Type &Node,                                             \
                  ::clang::ast_matchers::internal::ASTMatchFinder *Finder,      \
                  ::clang::ast_matchers::internal::BoundNodesTreeBuilder        \
@@ -147,12 +146,13 @@
   };                                                                           \
   }                                                                            \
   inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher(         \
-      ParamType const &Param) {                                                \
+      ParamType Param) {                                                       \
     return ::clang::ast_matchers::internal::makeMatcher(                       \
-        new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param));    \
+        new internal::matcher_##DefineMatcher##OverloadId##Matcher(            \
+            std::move(Param)));                                                \
   }                                                                            \
-  typedef ::clang::ast_matchers::internal::Matcher<Type>(                      \
-      &DefineMatcher##_Type##OverloadId)(ParamType const &Param);              \
+  typedef ::clang::ast_matchers::internal::Matcher<Type> (                     \
+      &DefineMatcher##_Type##OverloadId)(ParamType Param);                     \
   inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \
       const Type &Node,                                                        \
       ::clang::ast_matchers::internal::ASTMatchFinder *Finder,                 \
@@ -183,9 +183,9 @@
   class matcher_##DefineMatcher##OverloadId##Matcher                           \
       : public ::clang::ast_matchers::internal::MatcherInterface<Type> {       \
   public:                                                                      \
-    matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 const &A##Param1,  \
-                                                 ParamType2 const &A##Param2)  \
-        : Param1(A##Param1), Param2(A##Param2) {}                              \
+    matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 A##Param1,         \
+                                                 ParamType2 A##Param2)         \
+        : Param1(std::move(A##Param1)), Param2(std::move(A##Param2)) {}        \
     bool matches(const Type &Node,                                             \
                  ::clang::ast_matchers::internal::ASTMatchFinder *Finder,      \
                  ::clang::ast_matchers::internal::BoundNodesTreeBuilder        \
@@ -197,14 +197,14 @@
   };                                                                           \
   }                                                                            \
   inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher(         \
-      ParamType1 const &Param1, ParamType2 const &Param2) {                    \
+      ParamType1 Param1, ParamType2 Param2) {                                  \
     return ::clang::ast_matchers::internal::makeMatcher(                       \
-        new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param1,     \
-                                                                   Param2));   \
+        new internal::matcher_##DefineMatcher##OverloadId##Matcher(            \
+            std::move(Param1), std::move(Param2)));                            \
   }                                                                            \
-  typedef ::clang::ast_matchers::internal::Matcher<Type>(                      \
-      &DefineMatcher##_Type##OverloadId)(ParamType1 const &Param1,             \
-                                         ParamType2 const &Param2);            \
+  typedef ::clang::ast_matchers::internal::Matcher<Type> (                     \
+      &DefineMatcher##_Type##OverloadId)(ParamType1 Param1,                    \
+                                         ParamType2 Param2);                   \
   inline bool internal::matcher_##DefineMatcher##OverloadId##Matcher::matches( \
       const Type &Node,                                                        \
       ::clang::ast_matchers::internal::ASTMatchFinder *Finder,                 \
@@ -272,9 +272,8 @@
   class matcher_##DefineMatcher##OverloadId##Matcher                           \
       : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> {   \
   public:                                                                      \
-    explicit matcher_##DefineMatcher##OverloadId##Matcher(                     \
-        ParamType const &A##Param)                                             \
-        : Param(A##Param) {}                                                   \
+    explicit matcher_##DefineMatcher##OverloadId##Matcher(ParamType A##Param)  \
+        : Param(std::move(A##Param)) {}                                        \
     bool matches(const NodeType &Node,                                         \
                  ::clang::ast_matchers::internal::ASTMatchFinder *Finder,      \
                  ::clang::ast_matchers::internal::BoundNodesTreeBuilder        \
@@ -287,15 +286,14 @@
   inline ::clang::ast_matchers::internal::PolymorphicMatcherWithParam1<        \
       internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType,       \
       ReturnTypesF>                                                            \
-  DefineMatcher(ParamType const &Param) {                                      \
+  DefineMatcher(ParamType Param) {                                             \
     return ::clang::ast_matchers::internal::PolymorphicMatcherWithParam1<      \
         internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType,     \
-        ReturnTypesF>(Param);                                                  \
+        ReturnTypesF>(std::move(Param));                                       \
   }                                                                            \
   typedef ::clang::ast_matchers::internal::PolymorphicMatcherWithParam1<       \
       internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType,       \
-      ReturnTypesF>(&DefineMatcher##_Type##OverloadId)(                        \
-      ParamType const &Param);                                                 \
+      ReturnTypesF> (&DefineMatcher##_Type##OverloadId)(ParamType Param);      \
   template <typename NodeType, typename ParamT>                                \
   bool internal::                                                              \
       matcher_##DefineMatcher##OverloadId##Matcher<NodeType, ParamT>::matches( \
@@ -325,9 +323,9 @@
   class matcher_##DefineMatcher##OverloadId##Matcher                           \
       : public ::clang::ast_matchers::internal::MatcherInterface<NodeType> {   \
   public:                                                                      \
-    matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 const &A##Param1,  \
-                                                 ParamType2 const &A##Param2)  \
-        : Param1(A##Param1), Param2(A##Param2) {}                              \
+    matcher_##DefineMatcher##OverloadId##Matcher(ParamType1 A##Param1,         \
+                                                 ParamType2 A##Param2)         \
+        : Param1(std::move(A##Param1)), Param2(std::move(A##Param2)) {}        \
     bool matches(const NodeType &Node,                                         \
                  ::clang::ast_matchers::internal::ASTMatchFinder *Finder,      \
                  ::clang::ast_matchers::internal::BoundNodesTreeBuilder        \
@@ -341,15 +339,15 @@
   inline ::clang::ast_matchers::internal::PolymorphicMatcherWithParam2<        \
       internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType1,      \
       ParamType2, ReturnTypesF>                                                \
-  DefineMatcher(ParamType1 const &Param1, ParamType2 const &Param2) {          \
+  DefineMatcher(ParamType1 Param1, ParamType2 Param2) {                        \
     return ::clang::ast_matchers::internal::PolymorphicMatcherWithParam2<      \
         internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType1,    \
-        ParamType2, ReturnTypesF>(Param1, Param2);                             \
+        ParamType2, ReturnTypesF>(std::move(Param1), std::move(Param2));       \
   }                                                                            \
   typedef ::clang::ast_matchers::internal::PolymorphicMatcherWithParam2<       \
       internal::matcher_##DefineMatcher##OverloadId##Matcher, ParamType1,      \
-      ParamType2, ReturnTypesF>(&DefineMatcher##_Type##OverloadId)(            \
-      ParamType1 const &Param1, ParamType2 const &Param2);                     \
+      ParamType2, ReturnTypesF> (&DefineMatcher##_Type##OverloadId)(           \
+      ParamType1 Param1, ParamType2 Param2);                                   \
   template <typename NodeType, typename ParamT1, typename ParamT2>             \
   bool internal::matcher_##DefineMatcher##OverloadId##Matcher<                 \
       NodeType, ParamT1, ParamT2>::                                            \


        


More information about the cfe-commits mailing list