Skip to content

Commit 07181e2

Browse files
committed
[clang-format][NFC] Simplify getFirstNonComment() in the annotator
Differential Revision: https://reviews.llvm.org/D158104
1 parent 472a510 commit 07181e2

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4763,16 +4763,6 @@ static bool isAllmanLambdaBrace(const FormatToken &Tok) {
47634763
!Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral);
47644764
}
47654765

4766-
// Returns the first token on the line that is not a comment.
4767-
static const FormatToken *getFirstNonComment(const AnnotatedLine &Line) {
4768-
const FormatToken *Next = Line.First;
4769-
if (!Next)
4770-
return Next;
4771-
if (Next->is(tok::comment))
4772-
Next = Next->getNextNonComment();
4773-
return Next;
4774-
}
4775-
47764766
bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
47774767
const FormatToken &Right) const {
47784768
const FormatToken &Left = *Right.Previous;
@@ -5044,7 +5034,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
50445034
return Right.HasUnescapedNewline;
50455035

50465036
if (isAllmanBrace(Left) || isAllmanBrace(Right)) {
5047-
auto FirstNonComment = getFirstNonComment(Line);
5037+
auto *FirstNonComment = Line.getFirstNonComment();
50485038
bool AccessSpecifier =
50495039
FirstNonComment &&
50505040
FirstNonComment->isOneOf(Keywords.kw_internal, tok::kw_public,

clang/lib/Format/TokenAnnotator.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ class AnnotatedLine {
151151
startsWith(tok::kw_export, tok::kw_namespace);
152152
}
153153

154+
FormatToken *getFirstNonComment() const {
155+
assert(First);
156+
return First->is(tok::comment) ? First->getNextNonComment() : First;
157+
}
158+
154159
FormatToken *First;
155160
FormatToken *Last;
156161

0 commit comments

Comments
 (0)