[clang] 07b3446 - [clang-format] Never analyze insert/remove braces in the same pass

via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 14 22:43:35 PDT 2022


Author: owenca
Date: 2022-06-14T22:42:54-07:00
New Revision: 07b3446d72436c8372f50c43b45e46efe63182d9

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

LOG: [clang-format] Never analyze insert/remove braces in the same pass

Turn off RemoveBracesLLVM while analyzing InsertBraces and vice
versa to avoid potential interference of each other and better the
performance.

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

Added: 
    

Modified: 
    clang/lib/Format/Format.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 65a391dde3d57..df1aa9da16e39 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1833,7 +1833,9 @@ namespace {
 class BracesInserter : public TokenAnalyzer {
 public:
   BracesInserter(const Environment &Env, const FormatStyle &Style)
-      : TokenAnalyzer(Env, Style) {}
+      : TokenAnalyzer(Env, Style) {
+    this->Style.RemoveBracesLLVM = false;
+  }
 
   std::pair<tooling::Replacements, unsigned>
   analyze(TokenAnnotator &Annotator,
@@ -1875,7 +1877,9 @@ class BracesInserter : public TokenAnalyzer {
 class BracesRemover : public TokenAnalyzer {
 public:
   BracesRemover(const Environment &Env, const FormatStyle &Style)
-      : TokenAnalyzer(Env, Style) {}
+      : TokenAnalyzer(Env, Style) {
+    this->Style.InsertBraces = false;
+  }
 
   std::pair<tooling::Replacements, unsigned>
   analyze(TokenAnnotator &Annotator,


        


More information about the cfe-commits mailing list