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

For `UT_Never` the remaining results of the `max()` function are not needed, 
introduce a fast path for `UT_Never`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138378

Files:
  clang/lib/Format/WhitespaceManager.cpp


Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -1430,10 +1430,14 @@
       }
       // FIXME: This assert should hold if we computed the column correctly.
       // assert((int)C.StartOfTokenColumn >= C.Spaces);
-      appendIndentText(
-          ReplacementText, C.Tok->IndentLevel, std::max(0, C.Spaces),
-          std::max((int)C.StartOfTokenColumn, C.Spaces) - std::max(0, 
C.Spaces),
-          C.IsAligned);
+      unsigned Spaces = std::max(0, C.Spaces);
+      if (Style.UseTab == FormatStyle::UT_Never) {
+        ReplacementText.append(Spaces, ' ');
+      } else {
+        appendIndentText(ReplacementText, C.Tok->IndentLevel, Spaces,
+                         std::max((int)C.StartOfTokenColumn, C.Spaces) - 
Spaces,
+                         C.IsAligned);
+      }
       ReplacementText.append(C.CurrentLinePrefix);
       storeReplacement(C.OriginalWhitespaceRange, ReplacementText);
     }
@@ -1489,7 +1493,8 @@
                                          bool IsAligned) {
   switch (Style.UseTab) {
   case FormatStyle::UT_Never:
-    Text.append(Spaces, ' ');
+    assert(false);
+    llvm_unreachable("Manually handled");
     break;
   case FormatStyle::UT_Always: {
     if (Style.TabWidth) {


Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -1430,10 +1430,14 @@
       }
       // FIXME: This assert should hold if we computed the column correctly.
       // assert((int)C.StartOfTokenColumn >= C.Spaces);
-      appendIndentText(
-          ReplacementText, C.Tok->IndentLevel, std::max(0, C.Spaces),
-          std::max((int)C.StartOfTokenColumn, C.Spaces) - std::max(0, C.Spaces),
-          C.IsAligned);
+      unsigned Spaces = std::max(0, C.Spaces);
+      if (Style.UseTab == FormatStyle::UT_Never) {
+        ReplacementText.append(Spaces, ' ');
+      } else {
+        appendIndentText(ReplacementText, C.Tok->IndentLevel, Spaces,
+                         std::max((int)C.StartOfTokenColumn, C.Spaces) - Spaces,
+                         C.IsAligned);
+      }
       ReplacementText.append(C.CurrentLinePrefix);
       storeReplacement(C.OriginalWhitespaceRange, ReplacementText);
     }
@@ -1489,7 +1493,8 @@
                                          bool IsAligned) {
   switch (Style.UseTab) {
   case FormatStyle::UT_Never:
-    Text.append(Spaces, ' ');
+    assert(false);
+    llvm_unreachable("Manually handled");
     break;
   case FormatStyle::UT_Always: {
     if (Style.TabWidth) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to