Skip to content

Commit

Permalink
Memoize loc_t hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
kfcripps committed Jul 17, 2024
1 parent 18c06c9 commit 148e2d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions frontends/p4/def_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,13 @@ void ComputeWriteSet::visitVirtualMethods(const IR::IndexedVector<IR::Declaratio
}

std::size_t P4::loc_t::hash() const {
if (!parent) return Util::Hash{}(node->id);

return Util::Hash{}(node->id, parent->hash());
if (!computedHash) {
if (!parent)
computedHash = Util::Hash{}(node->id);
else
computedHash = Util::Hash{}(node->id, parent->hash());
}
return computedHash;
}

// Returns program location of n, given the program location of n's direct parent.
Expand Down
1 change: 1 addition & 0 deletions frontends/p4/def_use.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class LocationSet;
struct loc_t {
const IR::Node *node;
const loc_t *parent;
mutable std::size_t computedHash = 0;
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 148e2d4

Please sign in to comment.