@@ -782,19 +782,11 @@ _searchTypeMetadataRecords(TypeMetadataPrivateState &T,
782782
783783static const ConcurrencyStandardTypeDescriptors *concurrencyDescriptors;
784784
785+ // / Perform a fast-path lookup for standard library type references with short
786+ // / manglings. Returns the appropriate descriptor, or NULL if the descriptor
787+ // / couldn't be resolved, or if the node does not refer to one of those types.
785788static const ContextDescriptor *
786- _findContextDescriptor (Demangle::NodePointer node,
787- Demangle::Demangler &Dem) {
788- NodePointer symbolicNode = node;
789- if (symbolicNode->getKind () == Node::Kind::Type)
790- symbolicNode = symbolicNode->getChild (0 );
791-
792- // If we have a symbolic reference to a context, resolve it immediately.
793- if (symbolicNode->getKind () == Node::Kind::TypeSymbolicReference) {
794- return cast<TypeContextDescriptor>(
795- (const ContextDescriptor *)symbolicNode->getIndex ());
796- }
797-
789+ descriptorFromStandardMangling (Demangle::NodePointer symbolicNode) {
798790#if SWIFT_STDLIB_SHORT_MANGLING_LOOKUPS
799791 // Fast-path lookup for standard library type references with short manglings.
800792 if (symbolicNode->getNumChildren () >= 2
@@ -820,6 +812,24 @@ _findContextDescriptor(Demangle::NodePointer node,
820812#include " swift/Demangling/StandardTypesMangling.def"
821813 }
822814#endif
815+ return nullptr ;
816+ }
817+
818+ static const ContextDescriptor *
819+ _findContextDescriptor (Demangle::NodePointer node,
820+ Demangle::Demangler &Dem) {
821+ NodePointer symbolicNode = node;
822+ if (symbolicNode->getKind () == Node::Kind::Type)
823+ symbolicNode = symbolicNode->getChild (0 );
824+
825+ // If we have a symbolic reference to a context, resolve it immediately.
826+ if (symbolicNode->getKind () == Node::Kind::TypeSymbolicReference) {
827+ return cast<TypeContextDescriptor>(
828+ (const ContextDescriptor *)symbolicNode->getIndex ());
829+ }
830+
831+ if (auto *standardDescriptor = descriptorFromStandardMangling (symbolicNode))
832+ return standardDescriptor;
823833
824834 const ContextDescriptor *foundContext = nullptr ;
825835 auto &T = TypeMetadataRecords.get ();
@@ -984,8 +994,7 @@ _searchProtocolRecords(ProtocolMetadataPrivateState &C,
984994
985995static const ProtocolDescriptor *
986996_findProtocolDescriptor (NodePointer node,
987- Demangle::Demangler &Dem,
988- std::string &mangledName) {
997+ Demangle::Demangler &Dem) {
989998 const ProtocolDescriptor *foundProtocol = nullptr ;
990999 auto &T = Protocols.get ();
9911000
@@ -997,13 +1006,18 @@ _findProtocolDescriptor(NodePointer node,
9971006 return cast<ProtocolDescriptor>(
9981007 (const ContextDescriptor *)symbolicNode->getIndex ());
9991008
1009+ if (auto *standardDescriptor = descriptorFromStandardMangling (symbolicNode)) {
1010+ assert (standardDescriptor->getKind () == ContextDescriptorKind::Protocol);
1011+ return static_cast <const ProtocolDescriptor *>(standardDescriptor);
1012+ }
1013+
10001014 auto mangling =
10011015 Demangle::mangleNode (node, ExpandResolvedSymbolicReferences (Dem), Dem);
10021016
10031017 if (!mangling.isSuccess ())
10041018 return nullptr ;
10051019
1006- mangledName = mangling.result ().str ();
1020+ auto mangledName = mangling.result ().str ();
10071021
10081022 // Look for an existing entry.
10091023 // Find the bucket for the metadata entry.
@@ -1613,8 +1627,7 @@ class DecodedMetadataBuilder {
16131627
16141628 BuiltProtocolDecl createProtocolDecl (NodePointer node) const {
16151629 // Look for a protocol descriptor based on its mangled name.
1616- std::string mangledName;
1617- if (auto protocol = _findProtocolDescriptor (node, demangler, mangledName))
1630+ if (auto protocol = _findProtocolDescriptor (node, demangler))
16181631 return ProtocolDescriptorRef::forSwift (protocol);;
16191632
16201633#if SWIFT_OBJC_INTEROP
0 commit comments