File tree Expand file tree Collapse file tree 1 file changed +16
-12
lines changed Expand file tree Collapse file tree 1 file changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -850,6 +850,17 @@ struct ObjCBridgeMemo {
850850 destBridgeWitness, targetBridgedType);
851851 }
852852};
853+
854+ static const HashableWitnessTable* tryMemoizeNSStringHashableConformance (const Metadata *cls) {
855+ auto nsString = getNSStringMetadata ();
856+ do {
857+ if (cls == nsString) {
858+ return getNSStringHashableConformance ();
859+ }
860+ cls = _swift_class_getSuperclass (cls);
861+ } while (cls != nullptr );
862+ return nullptr ;
863+ }
853864#endif
854865
855866static DynamicCastResult
@@ -867,23 +878,16 @@ tryCastToAnyHashable(
867878 const HashableWitnessTable *hashableConformance = nullptr ;
868879
869880 switch (srcType->getKind ()) {
881+ case MetadataKind::Existential: {
882+ return DynamicCastResult::Failure;
883+ }
870884 case MetadataKind::ForeignClass: // CF -> String
871885 case MetadataKind::ObjCClassWrapper: { // Obj-C -> String
872886#if SWIFT_OBJC_INTEROP
873- auto cls = srcType;
874- auto nsString = getNSStringMetadata ();
875- do {
876- if (cls == nsString) {
877- hashableConformance = getNSStringHashableConformance ();
878- break ;
879- }
880- cls = _swift_class_getSuperclass (cls);
881- } while (cls != nullptr );
882- break ;
883- #else
887+ hashableConformance = tryMemoizeNSStringHashableConformance (srcType);
888+ #endif
884889 // If no Obj-C interop, just fall through to the general case.
885890 break ;
886- #endif
887891 }
888892 case MetadataKind::Optional: {
889893 // FIXME: https://github.com/apple/swift/issues/51550
You can’t perform that action at this time.
0 commit comments