[clang] 2dc435a - [clang][NFC] Use llvm::count_if instead of manual loop

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue May 16 06:36:51 PDT 2023


Author: Timm Bäder
Date: 2023-05-16T15:35:05+02:00
New Revision: 2dc435a59d565849ef62ae3c63dd4fc79a3e16f3

URL: https://github.com/llvm/llvm-project/commit/2dc435a59d565849ef62ae3c63dd4fc79a3e16f3
DIFF: https://github.com/llvm/llvm-project/commit/2dc435a59d565849ef62ae3c63dd4fc79a3e16f3.diff

LOG: [clang][NFC] Use llvm::count_if instead of manual loop

Added: 
    

Modified: 
    clang/lib/Frontend/DiagnosticRenderer.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Frontend/DiagnosticRenderer.cpp b/clang/lib/Frontend/DiagnosticRenderer.cpp
index 4cd7d982ed0e..18c8be7a7293 100644
--- a/clang/lib/Frontend/DiagnosticRenderer.cpp
+++ b/clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -494,10 +494,8 @@ static bool checkRangesForMacroArgExpansion(FullSourceLoc Loc,
   mapDiagnosticRanges(Loc, Ranges, SpellingRanges);
 
   // Count all valid ranges.
-  unsigned ValidCount = 0;
-  for (const auto &Range : Ranges)
-    if (Range.isValid())
-      ValidCount++;
+  unsigned ValidCount =
+      llvm::count_if(Ranges, [](const auto &R) { return R.isValid(); });
 
   if (ValidCount > SpellingRanges.size())
     return false;


        


More information about the cfe-commits mailing list