Skip to content

[Runtime] Shrink RemanglerBuffer's SubstitutionEntry. #81084

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
merged 1 commit into from
Apr 28, 2025
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
26 changes: 16 additions & 10 deletions lib/Demangling/RemanglerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "swift/Demangling/Demangler.h"
#include "swift/Demangling/NamespaceMacros.h"
#include "llvm/ADT/PointerIntPair.h"
#include <unordered_map>

using namespace swift::Demangle;
Expand All @@ -37,14 +38,19 @@ SWIFT_BEGIN_INLINE_NAMESPACE

// An entry in the remangler's substitution map.
class SubstitutionEntry {
Node *TheNode = nullptr;
llvm::PointerIntPair<Node *, 1, bool> NodeAndTreatAsIdentifier;
size_t StoredHash = 0;
bool treatAsIdentifier = false;

Node *getNode() const { return NodeAndTreatAsIdentifier.getPointer(); }

bool getTreatAsIdentifier() const {
return NodeAndTreatAsIdentifier.getInt();
}

public:
void setNode(Node *node, bool treatAsIdentifier, size_t hash) {
this->treatAsIdentifier = treatAsIdentifier;
TheNode = node;
NodeAndTreatAsIdentifier.setPointer(node);
NodeAndTreatAsIdentifier.setInt(treatAsIdentifier);
StoredHash = hash;
}

Expand All @@ -54,10 +60,10 @@ class SubstitutionEntry {
}
};

bool isEmpty() const { return !TheNode; }
bool isEmpty() const { return !getNode(); }

bool matches(Node *node, bool treatAsIdentifier) const {
return node == TheNode && treatAsIdentifier == this->treatAsIdentifier;
return node == getNode() && treatAsIdentifier == getTreatAsIdentifier();
}

size_t hash() const { return StoredHash; }
Expand All @@ -67,12 +73,12 @@ class SubstitutionEntry {
const SubstitutionEntry &rhs) {
if (lhs.StoredHash != rhs.StoredHash)
return false;
if (lhs.treatAsIdentifier != rhs.treatAsIdentifier)
if (lhs.getTreatAsIdentifier() != rhs.getTreatAsIdentifier())
return false;
if (lhs.treatAsIdentifier) {
return identifierEquals(lhs.TheNode, rhs.TheNode);
if (lhs.getTreatAsIdentifier()) {
return identifierEquals(lhs.getNode(), rhs.getNode());
}
return lhs.deepEquals(lhs.TheNode, rhs.TheNode);
return lhs.deepEquals(lhs.getNode(), rhs.getNode());
}

static bool identifierEquals(Node *lhs, Node *rhs);
Expand Down