Skip to content

[XRay] Use DenseMap::{operator[],try_emplace} (NFC) #107178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions llvm/include/llvm/XRay/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,20 +378,17 @@ class Graph {

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

/// Looks up the edge with identifier I, if it does not exist it default
/// constructs it, if it's endpoints do not exist it also default constructs
/// them.
EdgeAttribute &operator[](const EdgeIdentifier &I) {
auto &P = Edges.FindAndConstruct(I);
Vertices.FindAndConstruct(I.first);
Vertices.FindAndConstruct(I.second);
Vertices.try_emplace(I.first);
Vertices.try_emplace(I.second);
InNeighbors[I.second].insert(I.first);
OutNeighbors[I.first].insert(I.second);
return P.second;
return Edges[I];
}

/// Looks up a vertex with Identifier I, or an error if it does not exist.
Expand Down Expand Up @@ -479,8 +476,8 @@ class Graph {
auto EI = Val.first;
const auto &p = Edges.insert(std::move(Val));
if (p.second) {
Vertices.FindAndConstruct(EI.first);
Vertices.FindAndConstruct(EI.second);
Vertices.try_emplace(EI.first);
Vertices.try_emplace(EI.second);
InNeighbors[EI.second].insert(EI.first);
OutNeighbors[EI.first].insert(EI.second);
};
Expand Down
Loading