[clang] 42c564d - [clang-format][NFC] Make InsertNewlineAtEOF a little more efficient
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 9 01:09:53 PDT 2023
Author: Owen Pan
Date: 2023-10-09T01:09:45-07:00
New Revision: 42c564df2f479efb38e6f02340e370815b439eb1
URL: https://github.com/llvm/llvm-project/commit/42c564df2f479efb38e6f02340e370815b439eb1
DIFF: https://github.com/llvm/llvm-project/commit/42c564df2f479efb38e6f02340e370815b439eb1.diff
LOG: [clang-format][NFC] Make InsertNewlineAtEOF a little more efficient
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 6f879006465ecf5..543c119620bf28f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1414,10 +1414,6 @@ class AnnotatingParser {
Tok->setType(TT_TrailingReturnArrow);
}
break;
- case tok::eof:
- if (Style.InsertNewlineAtEOF && Tok->NewlinesBefore == 0)
- Tok->NewlinesBefore = 1;
- break;
default:
break;
}
@@ -3244,8 +3240,14 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
else if (Line.startsWith(TT_ObjCProperty))
Line.Type = LT_ObjCProperty;
- Line.First->SpacesRequiredBefore = 1;
- Line.First->CanBreakBefore = Line.First->MustBreakBefore;
+ auto *First = Line.First;
+ First->SpacesRequiredBefore = 1;
+ First->CanBreakBefore = First->MustBreakBefore;
+
+ if (First->is(tok::eof) && First->NewlinesBefore == 0 &&
+ Style.InsertNewlineAtEOF) {
+ First->NewlinesBefore = 1;
+ }
}
// This function heuristically determines whether 'Current' starts the name of a
More information about the cfe-commits
mailing list