19
19
20
20
#include " swift/Demangling/Demangler.h"
21
21
#include " swift/Demangling/NamespaceMacros.h"
22
+ #include " llvm/ADT/PointerIntPair.h"
22
23
#include < unordered_map>
23
24
24
25
using namespace swift ::Demangle;
@@ -37,14 +38,19 @@ SWIFT_BEGIN_INLINE_NAMESPACE
37
38
38
39
// An entry in the remangler's substitution map.
39
40
class SubstitutionEntry {
40
- Node *TheNode = nullptr ;
41
+ llvm::PointerIntPair< Node *, 1 , bool > NodeAndTreatAsIdentifier ;
41
42
size_t StoredHash = 0 ;
42
- bool treatAsIdentifier = false ;
43
+
44
+ Node *getNode () const { return NodeAndTreatAsIdentifier.getPointer (); }
45
+
46
+ bool getTreatAsIdentifier () const {
47
+ return NodeAndTreatAsIdentifier.getInt ();
48
+ }
43
49
44
50
public:
45
51
void setNode (Node *node, bool treatAsIdentifier, size_t hash) {
46
- this -> treatAsIdentifier = treatAsIdentifier ;
47
- TheNode = node ;
52
+ NodeAndTreatAsIdentifier. setPointer (node) ;
53
+ NodeAndTreatAsIdentifier. setInt (treatAsIdentifier) ;
48
54
StoredHash = hash;
49
55
}
50
56
@@ -54,10 +60,10 @@ class SubstitutionEntry {
54
60
}
55
61
};
56
62
57
- bool isEmpty () const { return !TheNode ; }
63
+ bool isEmpty () const { return !getNode () ; }
58
64
59
65
bool matches (Node *node, bool treatAsIdentifier) const {
60
- return node == TheNode && treatAsIdentifier == this -> treatAsIdentifier ;
66
+ return node == getNode () && treatAsIdentifier == getTreatAsIdentifier () ;
61
67
}
62
68
63
69
size_t hash () const { return StoredHash; }
@@ -67,12 +73,12 @@ class SubstitutionEntry {
67
73
const SubstitutionEntry &rhs) {
68
74
if (lhs.StoredHash != rhs.StoredHash )
69
75
return false ;
70
- if (lhs.treatAsIdentifier != rhs.treatAsIdentifier )
76
+ if (lhs.getTreatAsIdentifier () != rhs.getTreatAsIdentifier () )
71
77
return false ;
72
- if (lhs.treatAsIdentifier ) {
73
- return identifierEquals (lhs.TheNode , rhs.TheNode );
78
+ if (lhs.getTreatAsIdentifier () ) {
79
+ return identifierEquals (lhs.getNode () , rhs.getNode () );
74
80
}
75
- return lhs.deepEquals (lhs.TheNode , rhs.TheNode );
81
+ return lhs.deepEquals (lhs.getNode () , rhs.getNode () );
76
82
}
77
83
78
84
static bool identifierEquals (Node *lhs, Node *rhs);
0 commit comments