Skip to content

[clang-format][NFC] Minor efficiency cleanup #140835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/lib/Format/FormatToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,10 @@ struct FormatToken {
}

bool isObjCLifetimeQualifier(const FormatStyle &Style) const {
if (Style.Language != FormatStyle::LK_ObjC || !TokenText.starts_with("__"))
if (Style.Language != FormatStyle::LK_ObjC || isNot(tok::identifier) ||
!TokenText.starts_with("__")) {
return false;
}
const auto Qualifier = TokenText.substr(2);
return Qualifier == "autoreleasing" || Qualifier == "strong" ||
Qualifier == "weak" || Qualifier == "unsafe_unretained";
Expand Down
24 changes: 7 additions & 17 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ class AnnotatingParser {
Previous->setType(TT_SelectorName);
}
}
}
if (Style.isTableGen()) {
} else if (Style.isTableGen()) {
if (CurrentToken->isOneOf(tok::comma, tok::equal)) {
// They appear as separators. Unless they are not in class definition.
next();
Expand Down Expand Up @@ -3016,12 +3015,13 @@ class AnnotatingParser {
return TT_BinaryOperator;

const FormatToken *NextToken = Tok.getNextNonComment();
if (!NextToken)
return TT_PointerOrReference;

if (InTemplateArgument && NextToken && NextToken->is(tok::kw_noexcept))
if (InTemplateArgument && NextToken->is(tok::kw_noexcept))
return TT_BinaryOperator;

if (!NextToken ||
NextToken->isOneOf(tok::arrow, tok::equal, tok::comma, tok::r_paren,
if (NextToken->isOneOf(tok::arrow, tok::equal, tok::comma, tok::r_paren,
TT_RequiresClause) ||
(NextToken->is(tok::kw_noexcept) && !IsExpression) ||
NextToken->canBePointerOrReferenceQualifier() ||
Expand Down Expand Up @@ -6519,18 +6519,8 @@ TokenAnnotator::getTokenReferenceAlignment(const FormatToken &Reference) const {
FormatStyle::PointerAlignmentStyle
TokenAnnotator::getTokenPointerOrReferenceAlignment(
const FormatToken &PointerOrReference) const {
if (PointerOrReference.isOneOf(tok::amp, tok::ampamp)) {
switch (Style.ReferenceAlignment) {
case FormatStyle::RAS_Pointer:
return Style.PointerAlignment;
case FormatStyle::RAS_Left:
return FormatStyle::PAS_Left;
case FormatStyle::RAS_Right:
return FormatStyle::PAS_Right;
case FormatStyle::RAS_Middle:
return FormatStyle::PAS_Middle;
}
}
if (PointerOrReference.isOneOf(tok::amp, tok::ampamp))
return getTokenReferenceAlignment(PointerOrReference);
assert(PointerOrReference.is(tok::star));
return Style.PointerAlignment;
}
Expand Down