summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2018-12-14 21:14:44 +0000
committerAaron Ballman <aaron@aaronballman.com>2018-12-14 21:14:44 +0000
commit847e73d69c15626391da305609ae0282bee838fb (patch)
treee3c813b7f1a031904bf0bbfa00407486a13f17d1 /clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
parentce095c564aadd0c3974f2ef55d91a2931d008c68 (diff)
downloadbcm5719-llvm-847e73d69c15626391da305609ae0282bee838fb.tar.gz
bcm5719-llvm-847e73d69c15626391da305609ae0282bee838fb.zip
Using llvm::find_if() instead of a range-based for loop; NFC.
This addresses post-commit review feedback from r349188. llvm-svn: 349197
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
index 94894a393af..36046f0cfd1 100644
--- a/clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ b/clang/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<StringRef> 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<unsigned>(std::distance(Files.begin(), I));
+ if (I == Files.end())
Files.push_back(createFile(FE));
return json::Object{{"uri", FileURI}, {"fileIndex", Index}};
OpenPOWER on IntegriCloud