Also add an option "VectorLikeClasses" allowing user specify customized
vectors.
Details
- Reviewers
alexfh aaron.ballman - Commits
- rG489f3633805a: [clang-tidy] Support detecting for-range loop in inefficient-vector-operation…
rCTE301440: [clang-tidy] Support detecting for-range loop in inefficient-vector-operation…
rL301440: [clang-tidy] Support detecting for-range loop in inefficient-vector-operation…
Diff Detail
- Build Status
Buildable 5901 Build 5901: arc lint + arc unit
Event Timeline
docs/clang-tidy/checks/performance-inefficient-vector-operation.rst | ||
---|---|---|
5–6 | Please use `` to highlight language elements. Same below. |
Cool! A few nits.
clang-tidy/performance/InefficientVectorOperationCheck.cpp | ||
---|---|---|
56 | I'd just inline the expression and remove the local variable, since it doesn't seem to bring any benefits. | |
102 | s/Interested/Interesting/ | |
128 | It might be valuable to support more complex expressions here, though it would require more involved fixes, e.g. for (const auto& e : *source) v.push_back(e); -> v.reserve(source->size()); for (const auto& e : *source) v.push_back(e); or even like this: for (const auto& e : *some(complex)->container().expression()) v.push_back(e); -> const auto& source_container = *some(complex)->container().expression(); v.reserve(source_container.size()); for (const auto& e : source_container) v.push_back(e); Maybe leave a FIXME for this? | |
153 | const Stmt *LoopStmt = ForLoop ? ForLoop : RangeLoop; | |
184 | No need to qualify StringRef and Lexer. Here and a couple of other instances in this function. | |
197 | Does the check handle destination vector not being empty before the push_back loop? We'd need to reserve destination.size() + source.size() items in this case. If this is not handled yet, please add a FIXME. |
Thanks for the comments!
clang-tidy/performance/InefficientVectorOperationCheck.cpp | ||
---|---|---|
128 | Nice brainstorm, added a FIXME. | |
153 | We can't do it because ForLoop and RangeLoop are different types. | |
197 | This case should not happen, because we only find the push_back loop before which there are no usages (defined as DeclRefExpr that refers to vector`v`) of the vector v. |
LG
clang-tidy/performance/InefficientVectorOperationCheck.cpp | ||
---|---|---|
153 | nit: Please remove the extra space after the asterisk. | |
153 | Yup, static_cast<Stmt*> would be more ugly. This could still be shortened a bit: const Stmt *LoopStmt = ForLoop; if (!LoopStmt) LoopStmt = RangeLoop; Not that it makes too much difference though. Up to you. |
I'd just inline the expression and remove the local variable, since it doesn't seem to bring any benefits.