[clang-tidy] Add a clang-tidy check for possible inefficient vector operations
authorHaojian Wu <hokein@google.com>
Tue, 18 Apr 2017 07:46:39 +0000 (07:46 +0000)
committerHaojian Wu <hokein@google.com>
Tue, 18 Apr 2017 07:46:39 +0000 (07:46 +0000)
commitc5cc03377e10929be9490085cd1896107889f9c2
tree77b4b8250f963611539f0ed887ec4d3339fc2adb
parent74619721a9a22c5387fbd6f435492667d7373fda
[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
clang-tools-extra/clang-tidy/performance/CMakeLists.txt
clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp [new file with mode: 0644]
clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.h [new file with mode: 0644]
clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/docs/clang-tidy/checks/performance-inefficient-vector-operation.rst [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/performance-inefficient-vector-operation.cpp [new file with mode: 0644]