3939#include < vector>
4040#include < list>
4141#include < new>
42+ #include < cstring>
4243
4344using namespace swift ;
4445using namespace Demangle ;
@@ -472,6 +473,13 @@ static bool sameObjCTypeManglings(Demangle::NodePointer node1,
472473}
473474#endif
474475
476+ // / Optimization for the case where we need to compare a StringRef and a null terminated C string
477+ // / Not converting s2 to a StringRef avoids the need to call both strlen and memcmp
478+ static bool stringRefEqualsCString (StringRef s1, const char *s2) {
479+ size_t length = s1.size ();
480+ return strncmp (s1.data (), s2, length) == 0 && s2[length] == ' \0 ' ;
481+ }
482+
475483bool
476484swift::_contextDescriptorMatchesMangling (const ContextDescriptor *context,
477485 Demangle::NodePointer node) {
@@ -496,7 +504,7 @@ swift::_contextDescriptorMatchesMangling(const ContextDescriptor *context,
496504 // Match to a mangled module name.
497505 if (node->getKind () != Demangle::Node::Kind::Module)
498506 return false ;
499- if (!node->getText (). equals ( module ->Name .get ()))
507+ if (!stringRefEqualsCString ( node->getText (), module ->Name .get ()))
500508 return false ;
501509
502510 node = nullptr ;
@@ -568,7 +576,7 @@ swift::_contextDescriptorMatchesMangling(const ContextDescriptor *context,
568576 auto nameNode = node->getChild (1 );
569577 if (nameNode->getKind () != Demangle::Node::Kind::Identifier)
570578 return false ;
571- if (nameNode->getText () == proto->Name .get ()) {
579+ if (stringRefEqualsCString ( nameNode->getText (), proto->Name .get () )) {
572580 node = node->getChild (0 );
573581 break ;
574582 }
0 commit comments