summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2019-09-16 08:54:10 +0000
committerHaojian Wu <hokein@google.com>2019-09-16 08:54:10 +0000
commitad7a7cea89717daf6b56f35e4bc0b95afe0498a2 (patch)
tree0a1c2b56486350046143365ccb0f5672639793d7 /clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h
parentb026b3e53d67c258f8b750e3fc44fa1609185dee (diff)
downloadbcm5719-llvm-ad7a7cea89717daf6b56f35e4bc0b95afe0498a2.tar.gz
bcm5719-llvm-ad7a7cea89717daf6b56f35e4bc0b95afe0498a2.zip
[clang-tidy] performance-inefficient-vector-operation: Support proto repeated field
Summary: Finds calls that add element to protobuf repeated field in a loop without calling Reserve() before the loop. Calling Reserve() first can avoid unnecessary memory reallocations. A new option EnableProto is added to guard this feature. Patch by Cong Liu! Reviewers: gribozavr, alexfh, hokein, aaron.ballman Reviewed By: hokein Subscribers: lebedev.ri, xazax.hun, Eugene.Zelenko, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D67135 llvm-svn: 371963
Diffstat (limited to 'clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h')
-rw-r--r--clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h
index bfd84d100c2..e224dcc9068 100644
--- a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h
@@ -18,6 +18,9 @@ namespace performance {
/// Finds possible inefficient `std::vector` operations (e.g. `push_back`) in
/// for loops that may cause unnecessary memory reallocations.
///
+/// When EnableProto, also finds calls that add element to protobuf repeated
+/// field without calling Reserve() first.
+///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/performance-inefficient-vector-operation.html
class InefficientVectorOperationCheck : public ClangTidyCheck {
@@ -28,7 +31,14 @@ public:
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
private:
+ void AddMatcher(const ast_matchers::DeclarationMatcher &TargetRecordDecl,
+ StringRef VarDeclName, StringRef VarDeclStmtName,
+ const ast_matchers::DeclarationMatcher &AppendMethodDecl,
+ StringRef AppendCallName, ast_matchers::MatchFinder *Finder);
const std::vector<std::string> VectorLikeClasses;
+
+ // If true, also check inefficient operations for proto repeated fields.
+ bool EnableProto;
};
} // namespace performance
OpenPOWER on IntegriCloud