summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2017-04-18 07:46:39 +0000
committerHaojian Wu <hokein@google.com>2017-04-18 07:46:39 +0000
commitc5cc03377e10929be9490085cd1896107889f9c2 (patch)
tree77b4b8250f963611539f0ed887ec4d3339fc2adb /clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
parent74619721a9a22c5387fbd6f435492667d7373fda (diff)
downloadbcm5719-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.cpp3
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>(
OpenPOWER on IntegriCloud