[PATCH] D96516: Use MapVector to look up LoadedSourceFiles
Choongwoo Han via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 11 08:29:18 PST 2021
tunz created this revision.
tunz requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D96516
Files:
llvm/tools/llvm-cov/CodeCoverage.cpp
Index: llvm/tools/llvm-cov/CodeCoverage.cpp
===================================================================
--- llvm/tools/llvm-cov/CodeCoverage.cpp
+++ llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -20,6 +20,7 @@
#include "CoverageViewOptions.h"
#include "RenderingSupport.h"
#include "SourceCoverageView.h"
+#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
@@ -164,8 +165,7 @@
/// A container for input source file buffers.
std::mutex LoadedSourceFilesLock;
- std::vector<std::pair<std::string, std::unique_ptr<MemoryBuffer>>>
- LoadedSourceFiles;
+ MapVector<StringRef, std::unique_ptr<MemoryBuffer>> LoadedSourceFiles;
/// Whitelist from -name-whitelist to be used for filtering.
std::unique_ptr<SpecialCaseList> NameWhitelist;
@@ -248,17 +248,23 @@
if (Loc != RemappedFilenames.end())
SourceFile = Loc->second;
}
+
+ auto It = LoadedSourceFiles.find(SourceFile);
+ if (It != LoadedSourceFiles.end())
+ return *It->second;
+
for (const auto &Files : LoadedSourceFiles)
if (sys::fs::equivalent(SourceFile, Files.first))
return *Files.second;
+
auto Buffer = MemoryBuffer::getFile(SourceFile);
if (auto EC = Buffer.getError()) {
error(EC.message(), SourceFile);
return EC;
}
- LoadedSourceFiles.emplace_back(std::string(SourceFile),
- std::move(Buffer.get()));
- return *LoadedSourceFiles.back().second;
+
+ auto NewIt = LoadedSourceFiles.insert({SourceFile, std::move(Buffer.get())});
+ return *NewIt.first->second;
}
void CodeCoverageTool::attachExpansionSubViews(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96516.323032.patch
Type: text/x-patch
Size: 1668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210211/982a343c/attachment.bin>
More information about the llvm-commits
mailing list