[clang] c84d29a - [clang-format][NFC] Clean up IndentForLevel in LevelIndentTracker

via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 7 15:33:24 PDT 2022


Author: owenca
Date: 2022-07-07T15:33:09-07:00
New Revision: c84d29acbfa671b4a7fb24764cbd4bfa5f6aad5c

URL: https://github.com/llvm/llvm-project/commit/c84d29acbfa671b4a7fb24764cbd4bfa5f6aad5c
DIFF: https://github.com/llvm/llvm-project/commit/c84d29acbfa671b4a7fb24764cbd4bfa5f6aad5c.diff

LOG: [clang-format][NFC] Clean up IndentForLevel in LevelIndentTracker

Differential Revision: https://reviews.llvm.org/D129105

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineFormatter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 9a6f8884fcec..55a97addb3b1 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -59,8 +59,7 @@ class LevelIndentTracker {
     Offset = getIndentOffset(*Line.First);
     // Update the indent level cache size so that we can rely on it
     // having the right size in adjustToUnmodifiedline.
-    while (IndentForLevel.size() <= Line.Level)
-      IndentForLevel.push_back(-1);
+    skipLine(Line, /*UnknownIndent=*/true);
     if (Line.InPPDirective) {
       unsigned IndentWidth =
           (Style.PPIndentWidth >= 0) ? Style.PPIndentWidth : Style.IndentWidth;
@@ -76,9 +75,9 @@ class LevelIndentTracker {
 
   /// Update the indent state given that \p Line indent should be
   /// skipped.
-  void skipLine(const AnnotatedLine &Line) {
-    while (IndentForLevel.size() <= Line.Level)
-      IndentForLevel.push_back(Indent);
+  void skipLine(const AnnotatedLine &Line, bool UnknownIndent = false) {
+    if (Line.Level >= IndentForLevel.size())
+      IndentForLevel.resize(Line.Level + 1, UnknownIndent ? -1 : Indent);
   }
 
   /// Update the level indent to adapt to the given \p Line.
@@ -159,7 +158,7 @@ class LevelIndentTracker {
   const unsigned AdditionalIndent;
 
   /// The indent in characters for each level.
-  std::vector<int> IndentForLevel;
+  SmallVector<int> IndentForLevel;
 
   /// Offset of the current line relative to the indent level.
   ///


        


More information about the cfe-commits mailing list