Skip to content

Commit

Permalink
Use emplace() instead of insert()
Browse files Browse the repository at this point in the history
  • Loading branch information
kfcripps committed Jul 17, 2024
1 parent cd77c66 commit 2275e49
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
10 changes: 3 additions & 7 deletions frontends/p4/def_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,16 +773,14 @@ std::size_t P4::loc_t::hash() const {
// Use to get loc if n is indirect child (e.g. grandchild) of currently being visited node.
// In this case parentLoc is the loc of n's direct parent.
const P4::loc_t *ComputeWriteSet::getLoc(const IR::Node *n, const loc_t *parentLoc) {
loc_t tmp{n, parentLoc};
return &*cached_locs.insert(tmp).first;
return &*cached_locs.emplace(n, parentLoc).first;
}

// Returns program location given the context of the currently being visited node.
// Use to get loc of currently being visited node.
const P4::loc_t *ComputeWriteSet::getLoc(const Visitor::Context *ctxt) {
if (!ctxt) return nullptr;
loc_t tmp{ctxt->node, getLoc(ctxt->parent)};
return &*cached_locs.insert(tmp).first;
return &*cached_locs.emplace(ctxt->node, getLoc(ctxt->parent)).first;
}

// Returns program location of a child node n, given the context of the
Expand All @@ -791,9 +789,7 @@ const P4::loc_t *ComputeWriteSet::getLoc(const Visitor::Context *ctxt) {
const P4::loc_t *ComputeWriteSet::getLoc(const IR::Node *n, const Visitor::Context *ctxt) {
for (auto *p = ctxt; p; p = p->parent)
if (p->node == n) return getLoc(p);
auto rv = getLoc(ctxt);
loc_t tmp{n, rv};
return &*cached_locs.insert(tmp).first;
return &*cached_locs.emplace(n, getLoc(ctxt)).first;
}

// Symbolic execution of the parser
Expand Down
3 changes: 3 additions & 0 deletions frontends/p4/def_use.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class LocationSet;
struct loc_t {
const IR::Node *node;
const loc_t *parent;

loc_t(const IR::Node *node, const loc_t *parent) : node(node), parent(parent) {}

bool operator==(const loc_t &a) const {
if (node != a.node) return false;
if (parent == a.parent) return true;
Expand Down

0 comments on commit 2275e49

Please sign in to comment.