Skip to content

Commit a36aca5

Browse files
[sancov] Avoid repeated map lookups (NFC) (#109906)
1 parent c3fc763 commit a36aca5

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

llvm/tools/sancov/sancov.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,10 @@ static void operator<<(json::OStream &W,
323323
for (const auto &Loc : Point->Locs) {
324324
if (Loc.FileName != FileName || Loc.FunctionName != FunctionName)
325325
continue;
326-
if (WrittenIds.find(Point->Id) != WrittenIds.end())
326+
if (!WrittenIds.insert(Point->Id).second)
327327
continue;
328328

329329
// Output <point_id> : "<line>:<col>".
330-
WrittenIds.insert(Point->Id);
331330
W.attribute(Point->Id,
332331
(utostr(Loc.Line) + ":" + utostr(Loc.Column)));
333332
}
@@ -418,17 +417,15 @@ SymbolizedCoverage::read(const std::string &InputFile) {
418417
auto LineStr = Loc.substr(0, ColonPos);
419418
auto ColStr = Loc.substr(ColonPos + 1, Loc.size());
420419

421-
if (Points.find(PointId) == Points.end())
422-
Points.insert(std::make_pair(PointId, CoveragePoint(PointId)));
423-
424420
DILineInfo LineInfo;
425421
LineInfo.FileName = Filename;
426422
LineInfo.FunctionName = FunctionName;
427423
char *End;
428424
LineInfo.Line = std::strtoul(LineStr.c_str(), &End, 10);
429425
LineInfo.Column = std::strtoul(ColStr.c_str(), &End, 10);
430426

431-
CoveragePoint *CoveragePoint = &Points.find(PointId)->second;
427+
CoveragePoint *CoveragePoint =
428+
&Points.try_emplace(PointId, PointId).first->second;
432429
CoveragePoint->Locs.push_back(LineInfo);
433430
}
434431
}
@@ -576,10 +573,8 @@ getCoveragePoints(const std::string &ObjectFile,
576573
FrameInfo.FileName = normalizeFilename(FrameInfo.FileName);
577574
if (Ig.isIgnorelisted(FrameInfo))
578575
continue;
579-
if (Infos.find(FrameInfo) == Infos.end()) {
580-
Infos.insert(FrameInfo);
576+
if (Infos.insert(FrameInfo).second)
581577
Point.Locs.push_back(FrameInfo);
582-
}
583578
}
584579

585580
Result.push_back(Point);

0 commit comments

Comments
 (0)