Skip to content

Commit d5d8d8a

Browse files
authored
[clang-format][NFC] Minor efficiency cleanup (#140835)
1 parent 94fdeb7 commit d5d8d8a

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

clang/lib/Format/FormatToken.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,10 @@ struct FormatToken {
712712
}
713713

714714
bool isObjCLifetimeQualifier(const FormatStyle &Style) const {
715-
if (Style.Language != FormatStyle::LK_ObjC || !TokenText.starts_with("__"))
715+
if (Style.Language != FormatStyle::LK_ObjC || isNot(tok::identifier) ||
716+
!TokenText.starts_with("__")) {
716717
return false;
718+
}
717719
const auto Qualifier = TokenText.substr(2);
718720
return Qualifier == "autoreleasing" || Qualifier == "strong" ||
719721
Qualifier == "weak" || Qualifier == "unsafe_unretained";

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ class AnnotatingParser {
263263
Previous->setType(TT_SelectorName);
264264
}
265265
}
266-
}
267-
if (Style.isTableGen()) {
266+
} else if (Style.isTableGen()) {
268267
if (CurrentToken->isOneOf(tok::comma, tok::equal)) {
269268
// They appear as separators. Unless they are not in class definition.
270269
next();
@@ -3016,12 +3015,13 @@ class AnnotatingParser {
30163015
return TT_BinaryOperator;
30173016

30183017
const FormatToken *NextToken = Tok.getNextNonComment();
3018+
if (!NextToken)
3019+
return TT_PointerOrReference;
30193020

3020-
if (InTemplateArgument && NextToken && NextToken->is(tok::kw_noexcept))
3021+
if (InTemplateArgument && NextToken->is(tok::kw_noexcept))
30213022
return TT_BinaryOperator;
30223023

3023-
if (!NextToken ||
3024-
NextToken->isOneOf(tok::arrow, tok::equal, tok::comma, tok::r_paren,
3024+
if (NextToken->isOneOf(tok::arrow, tok::equal, tok::comma, tok::r_paren,
30253025
TT_RequiresClause) ||
30263026
(NextToken->is(tok::kw_noexcept) && !IsExpression) ||
30273027
NextToken->canBePointerOrReferenceQualifier() ||
@@ -6519,18 +6519,8 @@ TokenAnnotator::getTokenReferenceAlignment(const FormatToken &Reference) const {
65196519
FormatStyle::PointerAlignmentStyle
65206520
TokenAnnotator::getTokenPointerOrReferenceAlignment(
65216521
const FormatToken &PointerOrReference) const {
6522-
if (PointerOrReference.isOneOf(tok::amp, tok::ampamp)) {
6523-
switch (Style.ReferenceAlignment) {
6524-
case FormatStyle::RAS_Pointer:
6525-
return Style.PointerAlignment;
6526-
case FormatStyle::RAS_Left:
6527-
return FormatStyle::PAS_Left;
6528-
case FormatStyle::RAS_Right:
6529-
return FormatStyle::PAS_Right;
6530-
case FormatStyle::RAS_Middle:
6531-
return FormatStyle::PAS_Middle;
6532-
}
6533-
}
6522+
if (PointerOrReference.isOneOf(tok::amp, tok::ampamp))
6523+
return getTokenReferenceAlignment(PointerOrReference);
65346524
assert(PointerOrReference.is(tok::star));
65356525
return Style.PointerAlignment;
65366526
}

0 commit comments

Comments
 (0)