[llvm] a36aca5 - [sancov] Avoid repeated map lookups (NFC) (#109906)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 01:32:34 PDT 2024
Author: Kazu Hirata
Date: 2024-09-25T01:32:31-07:00
New Revision: a36aca5e189e8fd50af32060a25167e52e807f90
URL: https://github.com/llvm/llvm-project/commit/a36aca5e189e8fd50af32060a25167e52e807f90
DIFF: https://github.com/llvm/llvm-project/commit/a36aca5e189e8fd50af32060a25167e52e807f90.diff
LOG: [sancov] Avoid repeated map lookups (NFC) (#109906)
Added:
Modified:
llvm/tools/sancov/sancov.cpp
Removed:
################################################################################
diff --git a/llvm/tools/sancov/sancov.cpp b/llvm/tools/sancov/sancov.cpp
index dd51226e21311f..80f9996ba705ba 100644
--- a/llvm/tools/sancov/sancov.cpp
+++ b/llvm/tools/sancov/sancov.cpp
@@ -323,11 +323,10 @@ static void operator<<(json::OStream &W,
for (const auto &Loc : Point->Locs) {
if (Loc.FileName != FileName || Loc.FunctionName != FunctionName)
continue;
- if (WrittenIds.find(Point->Id) != WrittenIds.end())
+ if (!WrittenIds.insert(Point->Id).second)
continue;
// Output <point_id> : "<line>:<col>".
- WrittenIds.insert(Point->Id);
W.attribute(Point->Id,
(utostr(Loc.Line) + ":" + utostr(Loc.Column)));
}
@@ -418,9 +417,6 @@ SymbolizedCoverage::read(const std::string &InputFile) {
auto LineStr = Loc.substr(0, ColonPos);
auto ColStr = Loc.substr(ColonPos + 1, Loc.size());
- if (Points.find(PointId) == Points.end())
- Points.insert(std::make_pair(PointId, CoveragePoint(PointId)));
-
DILineInfo LineInfo;
LineInfo.FileName = Filename;
LineInfo.FunctionName = FunctionName;
@@ -428,7 +424,8 @@ SymbolizedCoverage::read(const std::string &InputFile) {
LineInfo.Line = std::strtoul(LineStr.c_str(), &End, 10);
LineInfo.Column = std::strtoul(ColStr.c_str(), &End, 10);
- CoveragePoint *CoveragePoint = &Points.find(PointId)->second;
+ CoveragePoint *CoveragePoint =
+ &Points.try_emplace(PointId, PointId).first->second;
CoveragePoint->Locs.push_back(LineInfo);
}
}
@@ -576,10 +573,8 @@ getCoveragePoints(const std::string &ObjectFile,
FrameInfo.FileName = normalizeFilename(FrameInfo.FileName);
if (Ig.isIgnorelisted(FrameInfo))
continue;
- if (Infos.find(FrameInfo) == Infos.end()) {
- Infos.insert(FrameInfo);
+ if (Infos.insert(FrameInfo).second)
Point.Locs.push_back(FrameInfo);
- }
}
Result.push_back(Point);
More information about the llvm-commits
mailing list