@@ -782,19 +782,11 @@ _searchTypeMetadataRecords(TypeMetadataPrivateState &T,
782
782
783
783
static const ConcurrencyStandardTypeDescriptors *concurrencyDescriptors;
784
784
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.
785
788
static 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) {
798
790
#if SWIFT_STDLIB_SHORT_MANGLING_LOOKUPS
799
791
// Fast-path lookup for standard library type references with short manglings.
800
792
if (symbolicNode->getNumChildren () >= 2
@@ -820,6 +812,24 @@ _findContextDescriptor(Demangle::NodePointer node,
820
812
#include " swift/Demangling/StandardTypesMangling.def"
821
813
}
822
814
#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;
823
833
824
834
const ContextDescriptor *foundContext = nullptr ;
825
835
auto &T = TypeMetadataRecords.get ();
@@ -984,8 +994,7 @@ _searchProtocolRecords(ProtocolMetadataPrivateState &C,
984
994
985
995
static const ProtocolDescriptor *
986
996
_findProtocolDescriptor (NodePointer node,
987
- Demangle::Demangler &Dem,
988
- std::string &mangledName) {
997
+ Demangle::Demangler &Dem) {
989
998
const ProtocolDescriptor *foundProtocol = nullptr ;
990
999
auto &T = Protocols.get ();
991
1000
@@ -997,13 +1006,18 @@ _findProtocolDescriptor(NodePointer node,
997
1006
return cast<ProtocolDescriptor>(
998
1007
(const ContextDescriptor *)symbolicNode->getIndex ());
999
1008
1009
+ if (auto *standardDescriptor = descriptorFromStandardMangling (symbolicNode)) {
1010
+ assert (standardDescriptor->getKind () == ContextDescriptorKind::Protocol);
1011
+ return static_cast <const ProtocolDescriptor *>(standardDescriptor);
1012
+ }
1013
+
1000
1014
auto mangling =
1001
1015
Demangle::mangleNode (node, ExpandResolvedSymbolicReferences (Dem), Dem);
1002
1016
1003
1017
if (!mangling.isSuccess ())
1004
1018
return nullptr ;
1005
1019
1006
- mangledName = mangling.result ().str ();
1020
+ auto mangledName = mangling.result ().str ();
1007
1021
1008
1022
// Look for an existing entry.
1009
1023
// Find the bucket for the metadata entry.
@@ -1613,8 +1627,7 @@ class DecodedMetadataBuilder {
1613
1627
1614
1628
BuiltProtocolDecl createProtocolDecl (NodePointer node) const {
1615
1629
// 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))
1618
1631
return ProtocolDescriptorRef::forSwift (protocol);;
1619
1632
1620
1633
#if SWIFT_OBJC_INTEROP
0 commit comments