[PATCH] D138378: [clang-format][NFC] Skip unneeded calculations

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 20 03:04:41 PST 2022


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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138378.476738.patch
Type: text/x-patch
Size: 1370 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221120/3aa215ef/attachment.bin>


More information about the cfe-commits mailing list