Skip to content

Commit cea6c03

Browse files
committed
[gardening] Use !empty() over size() > 0
1 parent f8a9e56 commit cea6c03

35 files changed

+58
-65
lines changed

include/swift/AST/ExistentialLayout.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ struct ExistentialLayout {
5050

5151
bool isObjC() const {
5252
// FIXME: Does the superclass have to be @objc?
53-
return ((superclass ||
54-
hasExplicitAnyObject ||
55-
getProtocols().size() > 0)
56-
&& !containsNonObjCProtocol);
53+
return ((superclass || hasExplicitAnyObject || !getProtocols().empty()) &&
54+
!containsNonObjCProtocol);
5755
}
5856

5957
/// Whether the existential requires a class, either via an explicit

include/swift/Migrator/Replacement.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@ struct Replacement {
2424
return Remove > 0;
2525
}
2626

27-
bool isInsert() const {
28-
return Remove == 0 && Text.size() > 0;
29-
}
27+
bool isInsert() const { return Remove == 0 && !Text.empty(); }
3028

31-
bool isReplace() const {
32-
return Remove > 0 && Text.size() > 0;
33-
}
29+
bool isReplace() const { return Remove > 0 && !Text.empty(); }
3430

3531
size_t endOffset() const {
3632
if (isInsert()) {

include/swift/SIL/SILFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ class SILFunction
473473
/// \returns True if the function is marked with the @_semantics attribute
474474
/// and has special semantics that the optimizer can use to optimize the
475475
/// function.
476-
bool hasSemanticsAttrs() const { return SemanticsAttrSet.size() > 0; }
476+
bool hasSemanticsAttrs() const { return !SemanticsAttrSet.empty(); }
477477

478478
/// \returns True if the function has a semantic attribute that starts with a
479479
/// specific string.

include/swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ClassHierarchyAnalysis : public SILAnalysis {
9393
/// in this module.
9494
bool hasKnownIndirectSubclasses(ClassDecl *C) {
9595
return IndirectSubclassesCache.count(C) &&
96-
IndirectSubclassesCache[C].size() > 0;
96+
!IndirectSubclassesCache[C].empty();
9797
}
9898

9999
/// Returns true if the protocol is implemented by any class in this module.

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ void ASTMangler::appendFunction(AnyFunctionType *fn, bool isFunctionMangling) {
16091609
else
16101610
appendOperator("_");
16111611
}
1612-
} else if (parameters.size() > 0) {
1612+
} else if (!parameters.empty()) {
16131613
appendOperator("y");
16141614
}
16151615

lib/AST/Decl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ void PatternBindingEntry::setInit(Expr *E) {
10901090
VarDecl *PatternBindingEntry::getAnchoringVarDecl() const {
10911091
SmallVector<VarDecl *, 8> variables;
10921092
getPattern()->collectVariables(variables);
1093-
assert(variables.size() > 0);
1093+
assert(!variables.empty());
10941094
return variables[0];
10951095
}
10961096

@@ -1685,8 +1685,8 @@ bool swift::conflicting(const OverloadSignature& sig1,
16851685
// If one is a compound name and the other is not, they do not conflict
16861686
// if one is a property and the other is a non-nullary function.
16871687
if (sig1.Name.isCompoundName() != sig2.Name.isCompoundName()) {
1688-
return !((sig1.IsProperty && sig2.Name.getArgumentNames().size() > 0) ||
1689-
(sig2.IsProperty && sig1.Name.getArgumentNames().size() > 0));
1688+
return !((sig1.IsProperty && !sig2.Name.getArgumentNames().empty()) ||
1689+
(sig2.IsProperty && !sig1.Name.getArgumentNames().empty()));
16901690
}
16911691

16921692
return sig1.Name == sig2.Name;

lib/AST/Identifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ llvm::raw_ostream &DeclName::print(llvm::raw_ostream &os,
157157
if (skipEmptyArgumentNames) {
158158
// If there is more than one argument yet none of them have names,
159159
// we're done.
160-
if (getArgumentNames().size() > 0) {
160+
if (!getArgumentNames().empty()) {
161161
bool anyNonEmptyNames = false;
162162
for (auto c : getArgumentNames()) {
163163
if (!c.empty()) {

lib/AST/NameLookupImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class FindLocalVal : public StmtVisitor<FindLocalVal> {
225225
}
226226
}
227227
}
228-
if (!inPatterns && items.size() > 0)
228+
if (!inPatterns && !items.empty())
229229
checkPattern(items[0].getPattern(), DeclVisibilityKind::LocalVariable);
230230
visit(body);
231231
}

lib/Basic/Unix/TaskQueue.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ bool TaskQueue::execute(TaskBeganCallback Began, TaskFinishedCallback Finished,
346346
ExecutingTasks[Pid] = std::move(T);
347347
}
348348

349-
assert(PollFds.size() > 0 &&
349+
assert(!PollFds.empty() &&
350350
"We should only call poll() if we have fds to watch!");
351351
int ReadyFdCount = poll(PollFds.data(), PollFds.size(), -1);
352352
if (ReadyFdCount == -1) {

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,8 +3402,7 @@ ClangImporter::Implementation::loadNamedMembers(
34023402
// prohibitively complex (also they're not stored in by-name lookup, for
34033403
// reasons unclear).
34043404
if (forEachLookupTable([&](SwiftLookupTable &table) -> bool {
3405-
return (table.lookupGlobalsAsMembers(
3406-
effectiveClangContext).size() > 0);
3405+
return (!table.lookupGlobalsAsMembers(effectiveClangContext).empty());
34073406
}))
34083407
return None;
34093408

0 commit comments

Comments
 (0)