owenpan created this revision.
owenpan added reviewers: curdeius, HazardyKnusperkeks, MyDeveloperDay.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129105

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -59,8 +59,7 @@
     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;
@@ -77,9 +76,11 @@
 
   /// 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) {
+    const auto Size = IndentForLevel.size();
+    if (Size <= Line.Level)
+      IndentForLevel.insert(IndentForLevel.end(), Line.Level - Size + 1,
+                            UnknownIndent ? -1 : Indent);
   }
 
   /// Update the level indent to adapt to the given \p Line.
@@ -159,7 +160,7 @@
   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.
   ///


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -59,8 +59,7 @@
     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;
@@ -77,9 +76,11 @@
 
   /// 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) {
+    const auto Size = IndentForLevel.size();
+    if (Size <= Line.Level)
+      IndentForLevel.insert(IndentForLevel.end(), Line.Level - Size + 1,
+                            UnknownIndent ? -1 : Indent);
   }
 
   /// Update the level indent to adapt to the given \p Line.
@@ -159,7 +160,7 @@
   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.
   ///
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to