diff options
author | Haojian Wu <hokein@google.com> | 2017-04-18 07:46:39 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2017-04-18 07:46:39 +0000 |
commit | c5cc03377e10929be9490085cd1896107889f9c2 (patch) | |
tree | 77b4b8250f963611539f0ed887ec4d3339fc2adb /clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp | |
parent | 74619721a9a22c5387fbd6f435492667d7373fda (diff) | |
download | bcm5719-llvm-c5cc03377e10929be9490085cd1896107889f9c2.tar.gz bcm5719-llvm-c5cc03377e10929be9490085cd1896107889f9c2.zip |
[clang-tidy] Add a clang-tidy check for possible inefficient vector operations
Summary:
The "performance-inefficient-vector-operation" check finds vector oprations in
for-loop statements which may cause multiple memory reallocations.
This is the first version, only detects typical for-loop:
```
std::vector<int> v;
for (int i = 0; i < n; ++i) {
v.push_back(i);
}
// or
for (int i = 0; i < v2.size(); ++i) {
v.push_back(v2[i]);
}
```
We can extend it to handle more cases like for-range loop in the future.
Reviewers: alexfh, aaron.ballman
Reviewed By: aaron.ballman
Subscribers: zaks.anna, Eugene.Zelenko, mgorny, cfe-commits, djasper
Differential Revision: https://reviews.llvm.org/D31757
llvm-svn: 300534
Diffstat (limited to 'clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp index 90255c5e2b6..072f817eedb 100644 --- a/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp @@ -14,6 +14,7 @@ #include "ForRangeCopyCheck.h" #include "ImplicitCastInLoopCheck.h" #include "InefficientStringConcatenationCheck.h" +#include "InefficientVectorOperationCheck.h" #include "TypePromotionInMathFnCheck.h" #include "UnnecessaryCopyInitialization.h" #include "UnnecessaryValueParamCheck.h" @@ -33,6 +34,8 @@ public: "performance-implicit-cast-in-loop"); CheckFactories.registerCheck<InefficientStringConcatenationCheck>( "performance-inefficient-string-concatenation"); + CheckFactories.registerCheck<InefficientVectorOperationCheck>( + "performance-inefficient-vector-operation"); CheckFactories.registerCheck<TypePromotionInMathFnCheck>( "performance-type-promotion-in-math-fn"); CheckFactories.registerCheck<UnnecessaryCopyInitialization>( |