[PATCH] D17491: Add performance check to flag function parameters of expensive to copy types that can be safely converted to const references.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 1 07:48:26 PST 2016


alexfh added inline comments.

================
Comment at: clang-tidy/performance/UnnecessaryValueParamCheck.cpp:25-32
@@ +24,10 @@
+std::string paramNameOrIndex(StringRef Name, size_t Index) {
+  std::string Output;
+  llvm::raw_string_ostream Stream(Output);
+  if (!Name.empty()) {
+    Stream << "'" << Name << "'";
+  } else {
+    Stream << "#" << ++Index;
+  }
+  return Stream.str();
+}
----------------
How about `return (Name.empty() ? llvm::Twine('#') + (Index + 1) : llvm::Twine('\'') + Name + '\'').str();` or something like this?

================
Comment at: clang-tidy/performance/UnnecessaryValueParamCheck.cpp:42
@@ +41,3 @@
+                  decl().bind("param"));
+  Finder->addMatcher(
+      functionDecl(isDefinition(), unless(cxxMethodDecl(isOverride())),
----------------
Can you first try adding tests with template parameter packs and C-style variadic functions?

================
Comment at: clang-tidy/performance/UnnecessaryValueParamCheck.cpp:56
@@ +55,3 @@
+                       Function->parameters().begin();
+  if (Index >= Function->getNumParams()) {
+    return;
----------------
nit: No braces around single-line `if` bodies.


http://reviews.llvm.org/D17491





More information about the cfe-commits mailing list