Skip to content

Commit 5ccbea9

Browse files
authored
[clang-format][NFC] Replace size() with empty() (#147164)
1 parent 6a9a16d commit 5ccbea9

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3582,7 +3582,7 @@ tooling::Replacements sortJavaImports(const FormatStyle &Style, StringRef Code,
35823582
ImportsInBlock.push_back(
35833583
{Identifier, Line, Prev, AssociatedCommentLines, IsStatic});
35843584
AssociatedCommentLines.clear();
3585-
} else if (Trimmed.size() > 0 && !ImportsInBlock.empty()) {
3585+
} else if (!Trimmed.empty() && !ImportsInBlock.empty()) {
35863586
// Associating comments within the imports with the nearest import below
35873587
AssociatedCommentLines.push_back(Line);
35883588
}

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,8 +1371,7 @@ FormatToken *FormatTokenLexer::getNextToken() {
13711371
} else if (FormatTok->TokenText == "``") {
13721372
FormatTok->Tok.setIdentifierInfo(nullptr);
13731373
FormatTok->Tok.setKind(tok::hashhash);
1374-
} else if (Tokens.size() > 0 &&
1375-
Tokens.back()->is(Keywords.kw_apostrophe) &&
1374+
} else if (!Tokens.empty() && Tokens.back()->is(Keywords.kw_apostrophe) &&
13761375
NumberBase.match(FormatTok->TokenText, &Matches)) {
13771376
// In Verilog in a based number literal like `'b10`, there may be
13781377
// whitespace between `'b` and `10`. Therefore we handle the base and
@@ -1420,7 +1419,7 @@ FormatToken *FormatTokenLexer::getNextToken() {
14201419
tryParseJavaTextBlock();
14211420
}
14221421

1423-
if (Style.isVerilog() && Tokens.size() > 0 &&
1422+
if (Style.isVerilog() && !Tokens.empty() &&
14241423
Tokens.back()->is(TT_VerilogNumberBase) &&
14251424
FormatTok->Tok.isOneOf(tok::identifier, tok::question)) {
14261425
// Mark the number following a base like `'h?a0` as a number.
@@ -1454,9 +1453,9 @@ FormatToken *FormatTokenLexer::getNextToken() {
14541453
if (Style.isCpp()) {
14551454
auto *Identifier = FormatTok->Tok.getIdentifierInfo();
14561455
auto it = Macros.find(Identifier);
1457-
if (!(Tokens.size() > 0 && Tokens.back()->Tok.getIdentifierInfo() &&
1458-
Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() ==
1459-
tok::pp_define) &&
1456+
if ((Tokens.empty() || !Tokens.back()->Tok.getIdentifierInfo() ||
1457+
Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() !=
1458+
tok::pp_define) &&
14601459
it != Macros.end()) {
14611460
FormatTok->setType(it->second);
14621461
if (it->second == TT_IfMacro) {

clang/lib/Format/QualifierAlignmentFixer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ bool isPossibleMacro(const FormatToken *Tok) {
640640
return false;
641641

642642
const auto Text = Tok->TokenText;
643-
assert(Text.size() > 0);
643+
assert(!Text.empty());
644644

645645
// T,K,U,V likely could be template arguments
646646
if (Text.size() == 1)

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ class LineJoiner {
223223
tryFitMultipleLinesInOne(LevelIndentTracker &IndentTracker,
224224
ArrayRef<AnnotatedLine *>::const_iterator I,
225225
ArrayRef<AnnotatedLine *>::const_iterator E) {
226-
const unsigned Indent = IndentTracker.getIndent();
227-
228226
// Can't join the last line with anything.
229227
if (I + 1 == E)
230228
return 0;
@@ -240,6 +238,7 @@ class LineJoiner {
240238
return 0;
241239
}
242240

241+
const auto Indent = IndentTracker.getIndent();
243242
if (Style.ColumnLimit > 0 && Indent > Style.ColumnLimit)
244243
return 0;
245244

@@ -1090,7 +1089,7 @@ class LineFormatter {
10901089
const FormatToken *LBrace = State.NextToken->getPreviousNonComment();
10911090
bool HasLBrace = LBrace && LBrace->is(tok::l_brace) && LBrace->is(BK_Block);
10921091
FormatToken &Previous = *State.NextToken->Previous;
1093-
if (Previous.Children.size() == 0 || (!HasLBrace && !LBrace->MacroParent)) {
1092+
if (Previous.Children.empty() || (!HasLBrace && !LBrace->MacroParent)) {
10941093
// The previous token does not open a block. Nothing to do. We don't
10951094
// assert so that we can simply call this function for all tokens.
10961095
return true;

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
314314

315315
for (unsigned i = Start; i != End; ++i) {
316316
auto &CurrentChange = Changes[i];
317-
if (ScopeStack.size() != 0 &&
317+
if (!ScopeStack.empty() &&
318318
CurrentChange.indentAndNestingLevel() <
319319
Changes[ScopeStack.back()].indentAndNestingLevel()) {
320320
ScopeStack.pop_back();
@@ -332,7 +332,7 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
332332
ScopeStack.push_back(i);
333333
}
334334

335-
bool InsideNestedScope = ScopeStack.size() != 0;
335+
bool InsideNestedScope = !ScopeStack.empty();
336336
bool ContinuedStringLiteral = i > Start &&
337337
CurrentChange.Tok->is(tok::string_literal) &&
338338
Changes[i - 1].Tok->is(tok::string_literal);
@@ -1048,7 +1048,7 @@ void WhitespaceManager::alignChainedConditionals() {
10481048
return C.Tok->is(TT_ConditionalExpr) &&
10491049
((C.Tok->is(tok::question) && !C.NewlinesBefore) ||
10501050
(C.Tok->is(tok::colon) && C.Tok->Next &&
1051-
(C.Tok->Next->FakeLParens.size() == 0 ||
1051+
(C.Tok->Next->FakeLParens.empty() ||
10521052
C.Tok->Next->FakeLParens.back() != prec::Conditional)));
10531053
},
10541054
Changes, /*StartAt=*/0);
@@ -1057,7 +1057,7 @@ void WhitespaceManager::alignChainedConditionals() {
10571057
FormatToken *Previous = C.Tok->getPreviousNonComment();
10581058
return C.NewlinesBefore && Previous && Previous->is(TT_ConditionalExpr) &&
10591059
(Previous->is(tok::colon) &&
1060-
(C.Tok->FakeLParens.size() == 0 ||
1060+
(C.Tok->FakeLParens.empty() ||
10611061
C.Tok->FakeLParens.back() != prec::Conditional));
10621062
};
10631063
// Ensure we keep alignment of wrapped operands with non-wrapped operands

0 commit comments

Comments
 (0)