@@ -38,36 +38,62 @@ static void unreachable(const char *Message) {
38
38
std::abort ();
39
39
}
40
40
41
+ static char getCharOfNodeText (Node *node, unsigned idx) {
42
+ switch (node->getKind ()) {
43
+ case Node::Kind::InfixOperator:
44
+ case Node::Kind::PrefixOperator:
45
+ case Node::Kind::PostfixOperator:
46
+ return Mangle::translateOperatorChar (node->getText ()[idx]);
47
+ default :
48
+ return node->getText ()[idx];
49
+ }
50
+ }
51
+
52
+ bool SubstitutionEntry::identifierEquals (Node *lhs, Node *rhs) {
53
+ unsigned length = lhs->getText ().size ();
54
+ if (rhs->getText ().size () != length)
55
+ return false ;
56
+ // The fast path.
57
+ if (lhs->getKind () == rhs->getKind ())
58
+ return lhs->getText () == rhs->getText ();
59
+ // The slow path.
60
+ for (unsigned i = 0 ; i < length; ++i) {
61
+ if (getCharOfNodeText (lhs, i) != getCharOfNodeText (rhs, i))
62
+ return false ;
63
+ }
64
+ return true ;
65
+ }
66
+
41
67
void SubstitutionEntry::deepHash (Node *node) {
42
68
if (treatAsIdentifier) {
43
69
combineHash ((size_t ) Node::Kind::Identifier);
44
- std::string tmp;
45
- combineHash (getTextForSubstitution (node, tmp));
46
- return ;
70
+ assert (node->hasText ());
71
+ switch (node->getKind ()) {
72
+ case Node::Kind::InfixOperator:
73
+ case Node::Kind::PrefixOperator:
74
+ case Node::Kind::PostfixOperator:
75
+ for (char c : node->getText ()) {
76
+ combineHash ((unsigned char )translateOperatorChar (c));
77
+ }
78
+ return ;
79
+ default :
80
+ break ;
81
+ }
82
+ } else {
83
+ combineHash ((size_t ) node->getKind ());
47
84
}
48
- combineHash ((size_t ) node->getKind ());
49
85
if (node->hasIndex ()) {
50
86
combineHash (node->getIndex ());
51
87
} else if (node->hasText ()) {
52
- combineHash (node->getText ());
88
+ for (char c : node->getText ()) {
89
+ combineHash ((unsigned char ) c);
90
+ }
53
91
}
54
92
for (Node *child : *node) {
55
93
deepHash (child);
56
94
}
57
95
}
58
96
59
- StringRef SubstitutionEntry::getTextForSubstitution (Node *node, std::string &tmp) {
60
- switch (node->getKind ()) {
61
- case Node::Kind::InfixOperator:
62
- case Node::Kind::PrefixOperator:
63
- case Node::Kind::PostfixOperator:
64
- tmp = Mangle::translateOperator (node->getText ());
65
- return tmp;
66
- default :
67
- return node->getText ();
68
- }
69
- }
70
-
71
97
bool SubstitutionEntry::deepEquals (Node *lhs, Node *rhs) const {
72
98
if (lhs->getKind () != rhs->getKind ())
73
99
return false ;
0 commit comments