[clang] [clang-format][NFC] AlignTokenSequence: Skip loop iteration (PR #68154)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 4 12:51:02 PDT 2023


https://github.com/HazardyKnusperkeks updated https://github.com/llvm/llvm-project/pull/68154

>From ca558ee22c4bc4749e3b7406364f3bbf8fb93ac9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= <bjoern at hazardy.de>
Date: Tue, 3 Oct 2023 17:32:47 +0200
Subject: [PATCH] [clang-format][NFC] AlignTokenSequence: Skip loop iteration

When Shift is 0 there does nothing happen in the remainder of the loop,
express that directly.
---
 clang/lib/Format/WhitespaceManager.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 4718c028cb5e44c..dc81060671c1712 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -354,6 +354,9 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
       }
     }
 
+    if (Shift == 0)
+      continue;
+
     // This is for function parameters that are split across multiple lines,
     // as mentioned in the ScopeStack comment.
     if (InsideNestedScope && CurrentChange.NewlinesBefore > 0) {
@@ -447,7 +450,7 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
       CurrentChange.Spaces += Shift;
 
     // We should not remove required spaces unless we break the line before.
-    assert(Shift >= 0 || Changes[i].NewlinesBefore > 0 ||
+    assert(Shift > 0 || Changes[i].NewlinesBefore > 0 ||
            CurrentChange.Spaces >=
                static_cast<int>(Changes[i].Tok->SpacesRequiredBefore) ||
            CurrentChange.Tok->is(tok::eof));



More information about the cfe-commits mailing list