[PATCH] D35787: [clang-tidy] Ignore vector<bool> in inefficient-vector-operation.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 24 01:44:09 PDT 2017
hokein created this revision.
Herald added subscribers: xazax.hun, JDevlieghere.
https://reviews.llvm.org/D35787
Files:
clang-tidy/performance/InefficientVectorOperationCheck.cpp
test/clang-tidy/performance-inefficient-vector-operation.cpp
Index: test/clang-tidy/performance-inefficient-vector-operation.cpp
===================================================================
--- test/clang-tidy/performance-inefficient-vector-operation.cpp
+++ test/clang-tidy/performance-inefficient-vector-operation.cpp
@@ -274,4 +274,12 @@
z12.push_back(e);
}
}
+ {
+ std::vector<bool> z14;
+ // std::vector<bool> will be ignored as STL provides a possibly
+ // space-efficient specilaization of std::vector for the type "bool".
+ for (int i = 0; i < 10; ++i) {
+ z14.push_back(true);
+ }
+ }
}
Index: clang-tidy/performance/InefficientVectorOperationCheck.cpp
===================================================================
--- clang-tidy/performance/InefficientVectorOperationCheck.cpp
+++ clang-tidy/performance/InefficientVectorOperationCheck.cpp
@@ -73,8 +73,13 @@
}
void InefficientVectorOperationCheck::registerMatchers(MatchFinder *Finder) {
- const auto VectorDecl = cxxRecordDecl(hasAnyName(SmallVector<StringRef, 5>(
- VectorLikeClasses.begin(), VectorLikeClasses.end())));
+ const auto VectorDecl = classTemplateSpecializationDecl(
+ hasAnyName(SmallVector<StringRef, 5>(VectorLikeClasses.begin(),
+ VectorLikeClasses.end())),
+ // Exclude std::vector<bool>: STL provides a specilaization of std::vector
+ // for the type "bool", which may be optimized for space efficiency (e.g.
+ // each element occupies a single bit instead of sizeof(bool) bytes).
+ unless(hasTemplateArgument(0, refersToType(booleanType()))));
const auto VectorDefaultConstructorCall = cxxConstructExpr(
hasType(VectorDecl),
hasDeclaration(cxxConstructorDecl(isDefaultConstructor())));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35787.107861.patch
Type: text/x-patch
Size: 1754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170724/4b4c074f/attachment.bin>
More information about the cfe-commits
mailing list