[PATCH] D90010: clang-tidy: Reduce number of stderr write calls

Hiral via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 22 22:30:37 PDT 2020


Hiralo created this revision.
Hiralo added reviewers: alexfh, njames93, hokein, DmitryPolukhin, djasper, ilya-biryukov.
Hiralo added a project: clang-tools-extra.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Hiralo requested review of this revision.

commit c3fa7da502d6cc77e5c0710b0e9308e6fbdd137c
Author: Hiral Oza <hiral.oza at netapp.com>
Date:   Thu Oct 22 22:06:25 2020 -0700

  clang-tidy: Reduce number of stderr write calls
  
  Making single write call in place of 7 small string write calls.

Thank you in advance for your kind review.
-Hiral


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90010

Files:
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp


Index: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
===================================================================
--- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -241,31 +241,36 @@
 namespace tidy {
 
 static void printStats(const ClangTidyStats &Stats) {
+  std::string Msg;
+  llvm::raw_string_ostream ErrStream(Msg);
+
   if (Stats.errorsIgnored()) {
-    llvm::errs() << "Suppressed " << Stats.errorsIgnored() << " warnings (";
+    ErrStream << "Suppressed " << Stats.errorsIgnored() << " warnings (";
+
     StringRef Separator = "";
     if (Stats.ErrorsIgnoredNonUserCode) {
-      llvm::errs() << Stats.ErrorsIgnoredNonUserCode << " in non-user code";
+      ErrStream << Stats.ErrorsIgnoredNonUserCode << " in non-user code";
       Separator = ", ";
     }
     if (Stats.ErrorsIgnoredLineFilter) {
-      llvm::errs() << Separator << Stats.ErrorsIgnoredLineFilter
-                   << " due to line filter";
+      ErrStream << Separator << Stats.ErrorsIgnoredLineFilter
+                << " due to line filter";
       Separator = ", ";
     }
     if (Stats.ErrorsIgnoredNOLINT) {
-      llvm::errs() << Separator << Stats.ErrorsIgnoredNOLINT << " NOLINT";
+      ErrStream << Separator << Stats.ErrorsIgnoredNOLINT << " NOLINT";
       Separator = ", ";
     }
     if (Stats.ErrorsIgnoredCheckFilter)
-      llvm::errs() << Separator << Stats.ErrorsIgnoredCheckFilter
-                   << " with check filters";
-    llvm::errs() << ").\n";
+      ErrStream << Separator << Stats.ErrorsIgnoredCheckFilter
+                << " with check filters";
+    ErrStream << ").\n";
     if (Stats.ErrorsIgnoredNonUserCode)
-      llvm::errs() << "Use -header-filter=.* to display errors from all "
-                      "non-system headers. Use -system-headers to display "
-                      "errors from system headers as well.\n";
+      ErrStream << "Use -header-filter=.* to display errors from all "
+                   "non-system headers. Use -system-headers to display "
+                   "errors from system headers as well.\n";
   }
+  llvm::errs() << ErrStream.str();
 }
 
 static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90010.300164.patch
Type: text/x-patch
Size: 2258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201023/bf899541/attachment-0001.bin>


More information about the cfe-commits mailing list