@@ -724,15 +724,33 @@ tryCastToAnyHashable(
724
724
assert (cast<StructMetadata>(destType)->Description
725
725
== &STRUCT_TYPE_DESCR_SYM (s11AnyHashable));
726
726
727
- auto hashableConformance = reinterpret_cast <const HashableWitnessTable *>(
727
+ switch (srcType->getKind ()) {
728
+ case MetadataKind::ForeignClass: // CF -> String
729
+ case MetadataKind::ObjCClassWrapper: { // Obj-C -> String
730
+ #if SWIFT_OBJC_INTEROP
731
+ // TODO: Implement a fast path for NSString->AnyHashable casts.
732
+ // These are incredibly common because an NSDictionary with
733
+ // NSString keys is bridged by default to [AnyHashable:Any].
734
+ // Until this is implemented, fall through to the default case
735
+ SWIFT_FALLTHROUGH;
736
+ #else
737
+ // If no Obj-C interop, just fall through to the default case.
738
+ SWIFT_FALLTHROUGH;
739
+ #endif
740
+ }
741
+ default : {
742
+ auto hashableConformance = reinterpret_cast <const HashableWitnessTable *>(
728
743
swift_conformsToProtocol (srcType, &HashableProtocolDescriptor));
729
- if (hashableConformance) {
730
- _swift_convertToAnyHashableIndirect (srcValue, destLocation,
731
- srcType, hashableConformance);
732
- return DynamicCastResult::SuccessViaCopy;
733
- } else {
734
- return DynamicCastResult::Failure;
744
+ if (hashableConformance) {
745
+ _swift_convertToAnyHashableIndirect (srcValue, destLocation,
746
+ srcType, hashableConformance);
747
+ return DynamicCastResult::SuccessViaCopy;
748
+ } else {
749
+ return DynamicCastResult::Failure;
750
+ }
735
751
}
752
+ }
753
+ return DynamicCastResult::Failure;
736
754
}
737
755
738
756
static DynamicCastResult
0 commit comments