From fce09f139ca076f1c59515ca3a44f272788faaf8 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 18 Oct 2012 20:09:54 +0000 Subject: [PATCH] Emit diagnostics in chunks even when we're trying to print colored template diffs. char-by-char is really slow on an unbuffered stream. llvm-svn: 166218 --- clang/lib/Frontend/TextDiagnostic.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp index a8a5613eaace..e47b5687ff49 100644 --- a/clang/lib/Frontend/TextDiagnostic.cpp +++ b/clang/lib/Frontend/TextDiagnostic.cpp @@ -43,19 +43,22 @@ static const enum raw_ostream::Colors savedColor = /// \brief Add highlights to differences in template strings. static void applyTemplateHighlighting(raw_ostream &OS, StringRef Str, bool &Normal, bool Bold) { - for (unsigned i = 0, e = Str.size(); i < e; ++i) - if (Str[i] != ToggleHighlight) { - OS << Str[i]; - } else { - if (Normal) - OS.changeColor(templateColor, true); - else { - OS.resetColor(); - if (Bold) - OS.changeColor(savedColor, true); - } - Normal = !Normal; + while (1) { + size_t Pos = Str.find(ToggleHighlight); + OS << Str.slice(0, Pos); + if (Pos == StringRef::npos) + break; + + Str = Str.substr(Pos + 1); + if (Normal) + OS.changeColor(templateColor, true); + else { + OS.resetColor(); + if (Bold) + OS.changeColor(savedColor, true); } + Normal = !Normal; + } } /// \brief Number of spaces to indent when word-wrapping.