Skip to content

Commit 58f2896

Browse files
[XRay] Use DenseMap::{operator[],try_emplace} (NFC) (#107178)
I'm planning to deprecate DenseMap::FindAndConstruct in favor of operator[]. I'm using try_emplace because "Vertices[I.first];" on its own might look like a nop statement.
1 parent 50febde commit 58f2896

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

llvm/include/llvm/XRay/Graph.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,20 +378,17 @@ class Graph {
378378

379379
/// Looks up the vertex with identifier I, if it does not exist it default
380380
/// constructs it.
381-
VertexAttribute &operator[](const VertexIdentifier &I) {
382-
return Vertices.FindAndConstruct(I).second;
383-
}
381+
VertexAttribute &operator[](const VertexIdentifier &I) { return Vertices[I]; }
384382

385383
/// Looks up the edge with identifier I, if it does not exist it default
386384
/// constructs it, if it's endpoints do not exist it also default constructs
387385
/// them.
388386
EdgeAttribute &operator[](const EdgeIdentifier &I) {
389-
auto &P = Edges.FindAndConstruct(I);
390-
Vertices.FindAndConstruct(I.first);
391-
Vertices.FindAndConstruct(I.second);
387+
Vertices.try_emplace(I.first);
388+
Vertices.try_emplace(I.second);
392389
InNeighbors[I.second].insert(I.first);
393390
OutNeighbors[I.first].insert(I.second);
394-
return P.second;
391+
return Edges[I];
395392
}
396393

397394
/// Looks up a vertex with Identifier I, or an error if it does not exist.
@@ -479,8 +476,8 @@ class Graph {
479476
auto EI = Val.first;
480477
const auto &p = Edges.insert(std::move(Val));
481478
if (p.second) {
482-
Vertices.FindAndConstruct(EI.first);
483-
Vertices.FindAndConstruct(EI.second);
479+
Vertices.try_emplace(EI.first);
480+
Vertices.try_emplace(EI.second);
484481
InNeighbors[EI.second].insert(EI.first);
485482
OutNeighbors[EI.first].insert(EI.second);
486483
};

0 commit comments

Comments
 (0)