@@ -38,36 +38,62 @@ static void unreachable(const char *Message) {
3838 std::abort ();
3939}
4040
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+
4167void SubstitutionEntry::deepHash (Node *node) {
4268 if (treatAsIdentifier) {
4369 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 ());
4784 }
48- combineHash ((size_t ) node->getKind ());
4985 if (node->hasIndex ()) {
5086 combineHash (node->getIndex ());
5187 } else if (node->hasText ()) {
52- combineHash (node->getText ());
88+ for (char c : node->getText ()) {
89+ combineHash ((unsigned char ) c);
90+ }
5391 }
5492 for (Node *child : *node) {
5593 deepHash (child);
5694 }
5795}
5896
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-
7197bool SubstitutionEntry::deepEquals (Node *lhs, Node *rhs) const {
7298 if (lhs->getKind () != rhs->getKind ())
7399 return false ;
0 commit comments