@@ -785,19 +785,11 @@ _searchTypeMetadataRecords(TypeMetadataPrivateState &T,
785
785
786
786
static const ConcurrencyStandardTypeDescriptors *concurrencyDescriptors;
787
787
788
+ // / Perform a fast-path lookup for standard library type references with short
789
+ // / manglings. Returns the appropriate descriptor, or NULL if the descriptor
790
+ // / couldn't be resolved, or if the node does not refer to one of those types.
788
791
static const ContextDescriptor *
789
- _findContextDescriptor (Demangle::NodePointer node,
790
- Demangle::Demangler &Dem) {
791
- NodePointer symbolicNode = node;
792
- if (symbolicNode->getKind () == Node::Kind::Type)
793
- symbolicNode = symbolicNode->getChild (0 );
794
-
795
- // If we have a symbolic reference to a context, resolve it immediately.
796
- if (symbolicNode->getKind () == Node::Kind::TypeSymbolicReference) {
797
- return cast<TypeContextDescriptor>(
798
- (const ContextDescriptor *)symbolicNode->getIndex ());
799
- }
800
-
792
+ descriptorFromStandardMangling (Demangle::NodePointer symbolicNode) {
801
793
#if SWIFT_STDLIB_SHORT_MANGLING_LOOKUPS
802
794
// Fast-path lookup for standard library type references with short manglings.
803
795
if (symbolicNode->getNumChildren () >= 2
@@ -823,6 +815,24 @@ _findContextDescriptor(Demangle::NodePointer node,
823
815
#include " swift/Demangling/StandardTypesMangling.def"
824
816
}
825
817
#endif
818
+ return nullptr ;
819
+ }
820
+
821
+ static const ContextDescriptor *
822
+ _findContextDescriptor (Demangle::NodePointer node,
823
+ Demangle::Demangler &Dem) {
824
+ NodePointer symbolicNode = node;
825
+ if (symbolicNode->getKind () == Node::Kind::Type)
826
+ symbolicNode = symbolicNode->getChild (0 );
827
+
828
+ // If we have a symbolic reference to a context, resolve it immediately.
829
+ if (symbolicNode->getKind () == Node::Kind::TypeSymbolicReference) {
830
+ return cast<TypeContextDescriptor>(
831
+ (const ContextDescriptor *)symbolicNode->getIndex ());
832
+ }
833
+
834
+ if (auto *standardDescriptor = descriptorFromStandardMangling (symbolicNode))
835
+ return standardDescriptor;
826
836
827
837
const ContextDescriptor *foundContext = nullptr ;
828
838
auto &T = TypeMetadataRecords.get ();
@@ -989,8 +999,7 @@ _searchProtocolRecords(ProtocolMetadataPrivateState &C,
989
999
990
1000
static const ProtocolDescriptor *
991
1001
_findProtocolDescriptor (NodePointer node,
992
- Demangle::Demangler &Dem,
993
- std::string &mangledName) {
1002
+ Demangle::Demangler &Dem) {
994
1003
const ProtocolDescriptor *foundProtocol = nullptr ;
995
1004
auto &T = Protocols.get ();
996
1005
@@ -1002,13 +1011,18 @@ _findProtocolDescriptor(NodePointer node,
1002
1011
return cast<ProtocolDescriptor>(
1003
1012
(const ContextDescriptor *)symbolicNode->getIndex ());
1004
1013
1014
+ if (auto *standardDescriptor = descriptorFromStandardMangling (symbolicNode)) {
1015
+ assert (standardDescriptor->getKind () == ContextDescriptorKind::Protocol);
1016
+ return static_cast <const ProtocolDescriptor *>(standardDescriptor);
1017
+ }
1018
+
1005
1019
auto mangling =
1006
1020
Demangle::mangleNode (node, ExpandResolvedSymbolicReferences (Dem), Dem);
1007
1021
1008
1022
if (!mangling.isSuccess ())
1009
1023
return nullptr ;
1010
1024
1011
- mangledName = mangling.result ().str ();
1025
+ auto mangledName = mangling.result ().str ();
1012
1026
1013
1027
// Look for an existing entry.
1014
1028
// Find the bucket for the metadata entry.
@@ -1622,8 +1636,7 @@ class DecodedMetadataBuilder {
1622
1636
1623
1637
BuiltProtocolDecl createProtocolDecl (NodePointer node) const {
1624
1638
// Look for a protocol descriptor based on its mangled name.
1625
- std::string mangledName;
1626
- if (auto protocol = _findProtocolDescriptor (node, demangler, mangledName))
1639
+ if (auto protocol = _findProtocolDescriptor (node, demangler))
1627
1640
return ProtocolDescriptorRef::forSwift (protocol);;
1628
1641
1629
1642
#if SWIFT_OBJC_INTEROP
0 commit comments