From: Aaron Ballman Date: Fri, 14 Dec 2018 21:14:44 +0000 (+0000) Subject: Using llvm::find_if() instead of a range-based for loop; NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a16197a4c0707d5e77c04ea46da663194b47a98;p=clang Using llvm::find_if() instead of a range-based for loop; NFC. This addresses post-commit review feedback from r349188. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349197 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp b/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp index 94894a393a..36046f0cfd 100644 --- a/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp +++ b/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp @@ -123,24 +123,21 @@ static json::Object createFileLocation(const FileEntry &FE, std::string FileURI = fileNameToURI(getFileName(FE)); // See if the Files array contains this URI already. If it does not, create - // a new file object to add to the array. Calculate the index within the file - // location array so it can be stored in the JSON object. - unsigned Index = 0; - for (const json::Value &File : Files) { + // a new file object to add to the array. + auto I = llvm::find_if(Files, [&](const json::Value &File) { if (const json::Object *Obj = File.getAsObject()) { if (const json::Object *FileLoc = Obj->getObject("fileLocation")) { Optional URI = FileLoc->getString("uri"); - if (URI && URI->equals(FileURI)) - break; + return URI && URI->equals(FileURI); } } - ++Index; - } + return false; + }); - // If we reached the end of the array, then add the file to the list of files - // we're tracking; Index then points to the last element of the array. Note - // that an empty file lists always causes a file to be added. - if (Files.empty() || Index == Files.size()) + // Calculate the index within the file location array so it can be stored in + // the JSON object. + auto Index = static_cast(std::distance(Files.begin(), I)); + if (I == Files.end()) Files.push_back(createFile(FE)); return json::Object{{"uri", FileURI}, {"fileIndex", Index}};