39
39
#include < vector>
40
40
#include < list>
41
41
#include < new>
42
+ #include < cstring>
42
43
43
44
using namespace swift ;
44
45
using namespace Demangle ;
@@ -472,6 +473,13 @@ static bool sameObjCTypeManglings(Demangle::NodePointer node1,
472
473
}
473
474
#endif
474
475
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
+
475
483
bool
476
484
swift::_contextDescriptorMatchesMangling (const ContextDescriptor *context,
477
485
Demangle::NodePointer node) {
@@ -496,7 +504,7 @@ swift::_contextDescriptorMatchesMangling(const ContextDescriptor *context,
496
504
// Match to a mangled module name.
497
505
if (node->getKind () != Demangle::Node::Kind::Module)
498
506
return false ;
499
- if (!node->getText (). equals ( module ->Name .get ()))
507
+ if (!stringRefEqualsCString ( node->getText (), module ->Name .get ()))
500
508
return false ;
501
509
502
510
node = nullptr ;
@@ -568,7 +576,7 @@ swift::_contextDescriptorMatchesMangling(const ContextDescriptor *context,
568
576
auto nameNode = node->getChild (1 );
569
577
if (nameNode->getKind () != Demangle::Node::Kind::Identifier)
570
578
return false ;
571
- if (nameNode->getText () == proto->Name .get ()) {
579
+ if (stringRefEqualsCString ( nameNode->getText (), proto->Name .get () )) {
572
580
node = node->getChild (0 );
573
581
break ;
574
582
}
0 commit comments