Skip to content

Commit 26d6502

Browse files
committed
[gardening] Use empty() over size() == 0
1 parent adfead0 commit 26d6502

27 files changed

+43
-43
lines changed

include/swift/Basic/Diff.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class diff_match_patch {
169169
Patch() : start1(0), start2(0), length1(0), length2(0) {}
170170

171171
bool isNull() const {
172-
return start1 == 0 && start2 == 0 && length1 == 0 && length2 == 0 && diffs.size() == 0;
172+
return start1 == 0 && start2 == 0 && length1 == 0 && length2 == 0 && diffs.empty();
173173
}
174174

175175
/**

include/swift/SILOptimizer/Analysis/BottomUpIPAnalysis.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class BottomUpIPAnalysis : public SILAnalysis {
181181
}
182182

183183
~BottomUpFunctionOrder() {
184-
assert(InitiallyUnscheduled.size() == 0 &&
184+
assert(InitiallyUnscheduled.empty() &&
185185
"not finished scheduling");
186186
assert(Scheduled.size() == numVisited &&
187187
"missed some functions to schedule");

lib/AST/ASTContext.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4289,7 +4289,7 @@ void DeclName::CompoundDeclName::Profile(llvm::FoldingSetNodeID &id,
42894289

42904290
void DeclName::initialize(ASTContext &C, DeclBaseName baseName,
42914291
ArrayRef<Identifier> argumentNames) {
4292-
if (argumentNames.size() == 0) {
4292+
if (argumentNames.empty()) {
42934293
SimpleOrCompound = BaseNameAndCompound(baseName, true);
42944294
return;
42954295
}

lib/AST/Builtins.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static ValueDecl *getBinaryPredicate(Identifier Id, Type ArgType) {
307307
static ValueDecl *getCastOperation(ASTContext &Context, Identifier Id,
308308
BuiltinValueKind VK,
309309
ArrayRef<Type> Types) {
310-
if (Types.size() == 0 || Types.size() > 2) return nullptr;
310+
if (Types.empty() || Types.size() > 2) return nullptr;
311311
Type Input = Types[0];
312312
Type Output = Types.size() == 2 ? Types[1] : Type();
313313

lib/AST/DocComment.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ bool extractParameterOutline(
141141
L->setChildren(NormalItems);
142142
}
143143

144-
return NormalItems.size() == 0;
144+
return NormalItems.empty();
145145
}
146146

147147
bool extractSeparatedParams(
@@ -205,7 +205,7 @@ bool extractSeparatedParams(
205205
if (NormalItems.size() != Children.size())
206206
L->setChildren(NormalItems);
207207

208-
return NormalItems.size() == 0;
208+
return NormalItems.empty();
209209
}
210210

211211
bool extractSimpleField(
@@ -280,7 +280,7 @@ bool extractSimpleField(
280280
if (NormalItems.size() != Children.size())
281281
L->setChildren(NormalItems);
282282

283-
return NormalItems.size() == 0;
283+
return NormalItems.empty();
284284
}
285285

286286
swift::markup::CommentParts

lib/AST/Expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ packSingleArgument(ASTContext &ctx, SourceLoc lParenLoc, ArrayRef<Expr *> args,
12071207

12081208
// If we have no other arguments, represent the trailing closure as a
12091209
// parenthesized expression.
1210-
if (args.size() == 0) {
1210+
if (args.empty()) {
12111211
auto arg = new (ctx) ParenExpr(lParenLoc, trailingClosure, rParenLoc,
12121212
/*hasTrailingClosure=*/true);
12131213
computeSingleArgumentType(ctx, arg, implicit, getType);

lib/AST/ProtocolConformance.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ ProtocolConformanceRef::getConditionalRequirements() const {
375375
}
376376

377377
void NormalProtocolConformance::differenceAndStoreConditionalRequirements() {
378-
assert(ConditionalRequirements.size() == 0 &&
378+
assert(ConditionalRequirements.empty() &&
379379
"should not recompute conditional requirements");
380380
auto &ctxt = getProtocol()->getASTContext();
381381
auto DC = getDeclContext();

lib/Basic/Version.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Optional<Version> Version::parseCompilerVersionString(
114114
bool isValidVersion = true;
115115

116116
auto checkVersionComponent = [&](unsigned Component, SourceRange Range) {
117-
unsigned limit = CV.Components.size() == 0 ? 9223371 : 999;
117+
unsigned limit = CV.Components.empty() ? 9223371 : 999;
118118

119119
if (Component > limit) {
120120
if (Diags)

lib/ClangImporter/ImportType.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ ImportedType ClangImporter::Implementation::importAccessorMethodType(
21912191

21922192
// Determine if the method is a property getter or setter.
21932193
bool isGetter;
2194-
if (clangDecl->parameters().size() == 0)
2194+
if (clangDecl->parameters().empty())
21952195
isGetter = true;
21962196
else if (clangDecl->parameters().size() == 1)
21972197
isGetter = false;

lib/Driver/ToolChain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ ToolChain::constructBatchJob(ArrayRef<const Job *> jobs,
284284
}
285285
}
286286
#endif
287-
if (jobs.size() == 0)
287+
if (jobs.empty())
288288
return nullptr;
289289

290290
// Synthetic OutputInfo is a slightly-modified version of the initial

lib/Frontend/ArgsToFrontendOutputsConverter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ SupplementaryOutputPathsComputer::getSupplementaryFilenamesFromArguments(
325325
if (paths.size() == N)
326326
return paths;
327327

328-
if (paths.size() == 0)
328+
if (paths.empty())
329329
return std::vector<std::string>(N, std::string());
330330

331331
Diags.diagnose(SourceLoc(), diag::error_wrong_number_of_arguments,

lib/IDE/Refactoring.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,7 @@ findConvertToTernaryExpression(ResolvedRangeInfo Info) {
20972097
&& Info.Kind != RangeKind::MultiStatement)
20982098
return notFound;
20992099

2100-
if (Info.ContainedNodes.size() == 0)
2100+
if (Info.ContainedNodes.empty())
21012101
return notFound;
21022102

21032103
struct AssignExprFinder: public SourceEntityWalker {
@@ -2529,7 +2529,7 @@ static CharSourceRange
25292529
ContextFinder Finder(*TheFile, Node, NodeChecker);
25302530
Finder.resolve();
25312531
auto Contexts = Finder.getContexts();
2532-
if (Contexts.size() == 0)
2532+
if (Contexts.empty())
25332533
return CharSourceRange();
25342534
auto TargetNode = Contexts.back();
25352535
BraceStmt *BStmt = dyn_cast<BraceStmt>(TargetNode.dyn_cast<Stmt*>());

lib/IDE/TypeReconstruction.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ static void VisitNodeFunction(
12081208
auto name = child->getChild(1); // First child is number.
12091209
FindNamedDecls(ast, ast->getIdentifier(name->getText()),
12101210
decl_scope_result);
1211-
if (decl_scope_result._decls.size() == 0) {
1211+
if (decl_scope_result._decls.empty()) {
12121212
llvm::raw_string_ostream OS(result._error);
12131213
OS << "demangled identifier " << name->getText()
12141214
<< " could not be found by name lookup";
@@ -1231,7 +1231,7 @@ static void VisitNodeFunction(
12311231
case Demangle::Node::Kind::PostfixOperator:
12321232
FindNamedDecls(ast, ast->getIdentifier((*pos)->getText()),
12331233
decl_scope_result);
1234-
if (decl_scope_result._decls.size() == 0) {
1234+
if (decl_scope_result._decls.empty()) {
12351235
result._error = stringWithFormat(
12361236
"demangled identifier %s could not be found by name lookup",
12371237
(*pos)->getText().str().c_str());

lib/IRGen/GenCall.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2920,7 +2920,7 @@ llvm::Value* IRGenFunction::coerceValue(llvm::Value *value, llvm::Type *toTy,
29202920

29212921
void IRGenFunction::emitScalarReturn(llvm::Type *resultType,
29222922
Explosion &result) {
2923-
if (result.size() == 0) {
2923+
if (result.empty()) {
29242924
Builder.CreateRetVoid();
29252925
return;
29262926
}
@@ -3008,7 +3008,7 @@ Explosion NativeConventionSchema::mapFromNative(IRGenModule &IGM,
30083008
IRGenFunction &IGF,
30093009
Explosion &native,
30103010
SILType type) const {
3011-
if (native.size() == 0) {
3011+
if (native.empty()) {
30123012
assert(empty() && "Empty explosion must match the native convention");
30133013
return Explosion();
30143014
}
@@ -3142,7 +3142,7 @@ Explosion NativeConventionSchema::mapIntoNative(IRGenModule &IGM,
31423142
Explosion &fromNonNative,
31433143
SILType type,
31443144
bool isOutlined) const {
3145-
if (fromNonNative.size() == 0) {
3145+
if (fromNonNative.empty()) {
31463146
assert(empty() && "Empty explosion must match the native convention");
31473147
return Explosion();
31483148
}
@@ -3275,7 +3275,7 @@ Explosion NativeConventionSchema::mapIntoNative(IRGenModule &IGM,
32753275

32763276
void IRGenFunction::emitScalarReturn(SILType resultType, Explosion &result,
32773277
bool isSwiftCCReturn, bool isOutlined) {
3278-
if (result.size() == 0) {
3278+
if (result.empty()) {
32793279
assert(IGM.getTypeInfo(resultType).nativeReturnValueSchema(IGM).empty() &&
32803280
"Empty explosion must match the native calling convention");
32813281

lib/IRGen/GenEnum.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3591,7 +3591,7 @@ namespace {
35913591
auto tagVal = llvm::ConstantInt::get(C, APInt(numTagBits, tagIndex));
35923592

35933593
// If the payload is empty, there's only one case per tag.
3594-
if (CommonSpareBits.size() == 0) {
3594+
if (CommonSpareBits.empty()) {
35953595
auto found = destMap.find(elti->decl);
35963596
if (found != destMap.end())
35973597
tagSwitch->addCase(tagVal, found->second);
@@ -3716,7 +3716,7 @@ namespace {
37163716
const LoadableTypeInfo &payloadTI,
37173717
Explosion &out) const {
37183718
// If the payload is empty, so is the explosion.
3719-
if (CommonSpareBits.size() == 0)
3719+
if (CommonSpareBits.empty())
37203720
return;
37213721

37223722
// If we have spare bits, we have to mask out any set tag bits packed
@@ -5243,7 +5243,7 @@ EnumImplStrategy::get(TypeConverter &TC, SILType type, EnumDecl *theEnum) {
52435243

52445244
// Enums imported from Clang or marked with @objc use C-compatible layout.
52455245
if (theEnum->hasClangNode() || theEnum->isObjC()) {
5246-
assert(elementsWithPayload.size() == 0 && "C enum with payload?!");
5246+
assert(elementsWithPayload.empty() && "C enum with payload?!");
52475247
assert(alwaysFixedSize == IsFixedSize && "C enum with resilient payload?!");
52485248
return std::unique_ptr<EnumImplStrategy>(
52495249
new CCompatibleEnumImplStrategy(TC.IGM, tik, alwaysFixedSize,

lib/IRGen/GenFunc.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ static bool isABIIgnoredParameterWithoutStorage(IRGenModule &IGM,
721721
getArgumentLoweringType(argType.getSwiftRValueType(), param);
722722
auto &ti = IGF.getTypeInfoForLowered(argLoweringTy);
723723
// Empty values don't matter.
724-
return ti.getSchema().size() == 0 && !param.isFormalIndirect();
724+
return ti.getSchema().empty() && !param.isFormalIndirect();
725725
}
726726

727727
/// Find the parameter index for the one (assuming there was only one) partially
@@ -1374,7 +1374,7 @@ void irgen::emitFunctionPartialApplication(
13741374

13751375
// Empty values don't matter.
13761376
auto schema = ti.getSchema();
1377-
if (schema.size() == 0 && !param.isFormalIndirect())
1377+
if (schema.empty() && !param.isFormalIndirect())
13781378
continue;
13791379

13801380
argValTypes.push_back(argType);

lib/IRGen/IRGenDebugInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
19511951
}
19521952

19531953
// Emit locationless intrinsic for variables that were optimized away.
1954-
if (Storage.size() == 0)
1954+
if (Storage.empty())
19551955
emitDbgIntrinsic(Builder, llvm::ConstantInt::get(IGM.Int64Ty, 0), Var,
19561956
DBuilder.createExpression(), Line, Loc.Column, Scope, DS);
19571957
}

lib/LLVMPasses/LLVMInlineTree.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class InlineTree {
117117
bool isTopLevel = false;
118118

119119
const NodeList &getChildren() {
120-
if (SortedChildren.size() == 0 && UnsortedChildren.size() > 0)
120+
if (SortedChildren.empty() && UnsortedChildren.size() > 0)
121121
sortNodes(UnsortedChildren, SortedChildren);
122122
return SortedChildren;
123123
}
@@ -274,7 +274,7 @@ void InlineTree::printNode(Node *Nd, int indent, raw_ostream &os) {
274274
void InlineTree::build(Module *M) {
275275
// Build the trees for all top-level functions.
276276
for (Function &F : *M) {
277-
if (F.size() == 0)
277+
if (F.empty())
278278
continue;
279279
buildTree(&F);
280280
}

lib/Parse/Lexer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void Lexer::formEscapedIdentifierToken(const char *TokStart) {
275275
assert(CurPtr[-1] == '`' && "escaped identifier ends with backtick");
276276
if (TriviaRetention == TriviaRetentionMode::WithTrivia) {
277277
LeadingTrivia.push_back(TriviaPiece::backtick());
278-
assert(TrailingTrivia.size() == 0 && "TrailingTrivia is empty here");
278+
assert(TrailingTrivia.empty() && "TrailingTrivia is empty here");
279279
TrailingTrivia.push_back(TriviaPiece::backtick());
280280
}
281281
formToken(tok::identifier, TokStart);

lib/PrintAsObjC/PrintAsObjC.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
620620
}
621621

622622
// Zero-parameter methods.
623-
if (params.size() == 0) {
623+
if (params.empty()) {
624624
assert(paramIndex == 0);
625625
os << piece;
626626
paramIndex = 1;

lib/SIL/SILInstructions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ AllocRefInstBase::AllocRefInstBase(SILInstructionKind Kind,
189189
SILInstruction::Bits.AllocRefInstBase.NumTailTypes = ElementTypes.size();
190190
assert(SILInstruction::Bits.AllocRefInstBase.NumTailTypes ==
191191
ElementTypes.size() && "Truncation");
192-
assert(!objc || ElementTypes.size() == 0);
192+
assert(!objc || ElementTypes.empty());
193193
}
194194

195195
AllocRefInst *AllocRefInst::create(SILDebugLocation Loc, SILFunction &F,
@@ -199,7 +199,7 @@ AllocRefInst *AllocRefInst::create(SILDebugLocation Loc, SILFunction &F,
199199
ArrayRef<SILValue> ElementCountOperands,
200200
SILOpenedArchetypesState &OpenedArchetypes) {
201201
assert(ElementTypes.size() == ElementCountOperands.size());
202-
assert(!objc || ElementTypes.size() == 0);
202+
assert(!objc || ElementTypes.empty());
203203
SmallVector<SILValue, 8> AllOperands(ElementCountOperands.begin(),
204204
ElementCountOperands.end());
205205
for (SILType ElemType : ElementTypes) {

lib/SIL/SILVerifier.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -3482,7 +3482,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
34823482
"switch_enum destination for case w/ args must take 1 "
34833483
"argument");
34843484
} else {
3485-
require(dest->getArguments().size() == 0 ||
3485+
require(dest->getArguments().empty() ||
34863486
dest->getArguments().size() == 1,
34873487
"switch_enum destination for case w/ args must take 0 or 1 "
34883488
"arguments");
@@ -3502,7 +3502,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
35023502
}
35033503

35043504
} else {
3505-
require(dest->getArguments().size() == 0,
3505+
require(dest->getArguments().empty(),
35063506
"switch_enum destination for no-argument case must take no "
35073507
"arguments");
35083508
}
@@ -3560,7 +3560,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
35603560
unswitchedElts.erase(elt);
35613561

35623562
// The destination BB must not have BB arguments.
3563-
require(dest->getArguments().size() == 0,
3563+
require(dest->getArguments().empty(),
35643564
"switch_enum_addr destination must take no BB args");
35653565
}
35663566

@@ -4704,7 +4704,7 @@ void SILWitnessTable::verify(const SILModule &M) const {
47044704
return;
47054705
#endif
47064706
if (isDeclaration())
4707-
assert(getEntries().size() == 0 &&
4707+
assert(getEntries().empty() &&
47084708
"A witness table declaration should not have any entries.");
47094709

47104710
auto *protocol = getConformance()->getProtocol();

lib/SILOptimizer/Analysis/SideEffectAnalysis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ void SideEffectAnalysis::recompute(FunctionInfo *Initial) {
483483
}
484484

485485
void SideEffectAnalysis::getEffects(FunctionEffects &ApplyEffects, FullApplySite FAS) {
486-
assert(ApplyEffects.ParamEffects.size() == 0 &&
486+
assert(ApplyEffects.ParamEffects.empty() &&
487487
"Not using a new ApplyEffects?");
488488
ApplyEffects.ParamEffects.resize(FAS.getNumArguments());
489489

lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ static void checkForViolationWithCall(
905905
const auto &SubAccesses = AS.getSubAccesses();
906906

907907
// Is the capture accessed in the callee?
908-
if (SubAccesses.size() == 0)
908+
if (SubAccesses.empty())
909909
continue;
910910

911911
SILValue Argument = Arguments[ArgumentIndex];
@@ -1297,7 +1297,7 @@ static void checkStaticExclusivity(SILFunction &Fn, PostOrderFunctionInfo *PO,
12971297
}
12981298
#endif
12991299
// Sanity check to make sure entries are properly removed.
1300-
assert((!isa<ReturnInst>(&I) || Accesses.size() == 0) &&
1300+
assert((!isa<ReturnInst>(&I) || Accesses.empty()) &&
13011301
"Entries were not properly removed?!");
13021302
}
13031303
}

lib/SILOptimizer/Transforms/CopyForwarding.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ void CopyForwarding::forwardCopiesOf(SILValue Def, SILFunction *F) {
12231223
for (auto *BB : PostOrder->get(F)->getPostOrder()) {
12241224
SmallVector<unsigned, 4> DeadInSuccs;
12251225
ArrayRef<SILSuccessor> Succs = BB->getSuccessors();
1226-
if (Succs.size() == 0)
1226+
if (Succs.empty())
12271227
continue;
12281228

12291229
for (unsigned EdgeIdx = 0, End = Succs.size(); EdgeIdx != End; ++EdgeIdx) {

lib/Sema/CSDiag.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4465,7 +4465,7 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
44654465
if (instTy->getAnyNominal()) {
44664466
// If we are invoking a constructor on a nominal type and there are
44674467
// absolutely no candidates, then they must all be private.
4468-
if (CCI.size() == 0 || (CCI.size() == 1 && CCI.candidates[0].getDecl() &&
4468+
if (CCI.empty() || (CCI.size() == 1 && CCI.candidates[0].getDecl() &&
44694469
isa<ProtocolDecl>(CCI.candidates[0].getDecl()))) {
44704470
CS.TC.diagnose(fnExpr->getLoc(), diag::no_accessible_initializers,
44714471
instTy);

lib/Sema/TypeCheckAvailability.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class TypeRefinementContextBuilder : private ASTWalker {
433433
// If this query expression has no queries, we will not introduce a new
434434
// refinement context. We do not diagnose here: a diagnostic will already
435435
// have been emitted by the parser.
436-
if (Query->getQueries().size() == 0)
436+
if (Query->getQueries().empty())
437437
continue;
438438

439439
AvailabilitySpec *Spec = bestActiveSpecForQuery(Query);

0 commit comments

Comments
 (0)