[PATCH] Replace size calls on containers with empty calls where appropriate
Gábor Horváth
xazax.hun at gmail.com
Wed Jan 21 03:55:22 PST 2015
Replace size calls on containers with empty calls where appropriate. This patch is the result of applying the fixits of the recently committed readability-container-size-empty checker in clang tidy. A similar patch was committed to the backend already: http://reviews.llvm.org/rL226161
All the tests are passed on my machine.
http://reviews.llvm.org/D7090
Files:
examples/PrintFunctionNames/PrintFunctionNames.cpp
lib/CodeGen/BackendUtil.cpp
lib/CodeGen/CGObjCGNU.cpp
tools/libclang/CIndex.cpp
utils/TableGen/ClangAttrEmitter.cpp
utils/TableGen/NeonEmitter.cpp
Index: examples/PrintFunctionNames/PrintFunctionNames.cpp
===================================================================
--- examples/PrintFunctionNames/PrintFunctionNames.cpp
+++ examples/PrintFunctionNames/PrintFunctionNames.cpp
@@ -55,7 +55,7 @@
return false;
}
}
- if (args.size() && args[0] == "help")
+ if (!args.empty() && args[0] == "help")
PrintHelp(llvm::errs());
return true;
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -432,7 +432,7 @@
BackendArgs.data());
std::string FeaturesStr;
- if (TargetOpts.Features.size()) {
+ if (!TargetOpts.Features.empty()) {
SubtargetFeatures Features;
for (std::vector<std::string>::const_iterator
it = TargetOpts.Features.begin(),
Index: lib/CodeGen/CGObjCGNU.cpp
===================================================================
--- lib/CodeGen/CGObjCGNU.cpp
+++ lib/CodeGen/CGObjCGNU.cpp
@@ -2366,7 +2366,7 @@
std::vector<llvm::Constant*> Elements;
llvm::Constant *Statics = NULLPtr;
// Generate statics list:
- if (ConstantStrings.size()) {
+ if (!ConstantStrings.empty()) {
llvm::ArrayType *StaticsArrayTy = llvm::ArrayType::get(PtrToInt8Ty,
ConstantStrings.size() + 1);
ConstantStrings.push_back(NULLPtr);
Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -6943,7 +6943,7 @@
CXTUResourceUsage usage = { (void*) entries.get(),
(unsigned) entries->size(),
- entries->size() ? &(*entries)[0] : nullptr };
+ !entries->empty() ? &(*entries)[0] : nullptr };
entries.release();
return usage;
}
Index: utils/TableGen/ClangAttrEmitter.cpp
===================================================================
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -1207,7 +1207,7 @@
static unsigned
getSpellingListIndex(const std::vector<FlattenedSpelling> &SpellingList,
const FlattenedSpelling &Spelling) {
- assert(SpellingList.size() && "Spelling list is empty!");
+ assert(!SpellingList.empty() && "Spelling list is empty!");
for (unsigned Index = 0; Index < SpellingList.size(); ++Index) {
const FlattenedSpelling &S = SpellingList[Index];
@@ -1231,7 +1231,7 @@
std::vector<FlattenedSpelling> Spellings =
GetFlattenedSpellings(*Accessor);
std::vector<FlattenedSpelling> SpellingList = GetFlattenedSpellings(R);
- assert(SpellingList.size() &&
+ assert(!SpellingList.empty() &&
"Attribute with empty spelling list can't have accessors!");
OS << " bool " << Name << "() const { return SpellingListIndex == ";
Index: utils/TableGen/NeonEmitter.cpp
===================================================================
--- utils/TableGen/NeonEmitter.cpp
+++ utils/TableGen/NeonEmitter.cpp
@@ -1393,7 +1393,7 @@
}
}
- assert(Lines.size() && "Empty def?");
+ assert(!Lines.empty() && "Empty def?");
if (!RetVar.getType().isVoid())
Lines.back().insert(0, RetVar.getName() + " = ");
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7090.18499.patch
Type: text/x-patch
Size: 3327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150121/669434e2/attachment.bin>
More information about the cfe-commits
mailing list