This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG49843c503684: [clang][Diagnostics] Simplify emitSnippet() 
(authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151075/new/

https://reviews.llvm.org/D151075

Files:
  clang/lib/Frontend/TextDiagnostic.cpp


Index: clang/lib/Frontend/TextDiagnostic.cpp
===================================================================
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1314,30 +1314,27 @@
     OS << " | ";
   }
 
+  // Print the source line one character at a time.
   bool PrintReversed = false;
-  std::string ToPrint;
   size_t I = 0;
   while (I < SourceLine.size()) {
     auto [Str, WasPrintable] =
         printableTextForNextCharacter(SourceLine, &I, DiagOpts->TabStop);
 
-    if (DiagOpts->ShowColors && WasPrintable == PrintReversed) {
-      if (PrintReversed)
-        OS.reverseColor();
-      OS << ToPrint;
-      ToPrint.clear();
-      if (DiagOpts->ShowColors)
-        OS.resetColor();
+    // Toggle inverted colors on or off for this character.
+    if (DiagOpts->ShowColors) {
+      if (WasPrintable == PrintReversed) {
+        PrintReversed = !PrintReversed;
+        if (PrintReversed)
+          OS.reverseColor();
+        else
+          OS.resetColor();
+      }
     }
-
-    PrintReversed = !WasPrintable;
-    ToPrint += Str;
+    OS << Str;
   }
 
-  if (PrintReversed && DiagOpts->ShowColors)
-    OS.reverseColor();
-  OS << ToPrint;
-  if (PrintReversed && DiagOpts->ShowColors)
+  if (DiagOpts->ShowColors)
     OS.resetColor();
 
   OS << '\n';


Index: clang/lib/Frontend/TextDiagnostic.cpp
===================================================================
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1314,30 +1314,27 @@
     OS << " | ";
   }
 
+  // Print the source line one character at a time.
   bool PrintReversed = false;
-  std::string ToPrint;
   size_t I = 0;
   while (I < SourceLine.size()) {
     auto [Str, WasPrintable] =
         printableTextForNextCharacter(SourceLine, &I, DiagOpts->TabStop);
 
-    if (DiagOpts->ShowColors && WasPrintable == PrintReversed) {
-      if (PrintReversed)
-        OS.reverseColor();
-      OS << ToPrint;
-      ToPrint.clear();
-      if (DiagOpts->ShowColors)
-        OS.resetColor();
+    // Toggle inverted colors on or off for this character.
+    if (DiagOpts->ShowColors) {
+      if (WasPrintable == PrintReversed) {
+        PrintReversed = !PrintReversed;
+        if (PrintReversed)
+          OS.reverseColor();
+        else
+          OS.resetColor();
+      }
     }
-
-    PrintReversed = !WasPrintable;
-    ToPrint += Str;
+    OS << Str;
   }
 
-  if (PrintReversed && DiagOpts->ShowColors)
-    OS.reverseColor();
-  OS << ToPrint;
-  if (PrintReversed && DiagOpts->ShowColors)
+  if (DiagOpts->ShowColors)
     OS.resetColor();
 
   OS << '\n';
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to