@@ -619,8 +619,15 @@ bool _swift_dictionaryDownCastConditionalIndirect(OpaqueValue *destination,
619
619
// Swift struct type. This is used to speed up the most common
620
620
// ObjC->Swift bridging conversions by eliminating repeeated
621
621
// protocol conformance lookups.
622
+
623
+ // Currently used only for String, which may be the only
624
+ // type used often enough to justify the extra static memory.
622
625
struct ObjCBridgeMemo {
626
+ #if !NDEBUG
627
+ // Used in assert build to verify that we always get called with
628
+ // the same destType
623
629
const Metadata *destType;
630
+ #endif
624
631
const _ObjectiveCBridgeableWitnessTable *destBridgeWitness;
625
632
const Metadata *targetBridgedType;
626
633
Class targetBridgedObjCClass;
@@ -641,21 +648,25 @@ struct ObjCBridgeMemo {
641
648
[](void *data) {
642
649
struct SetupData *setupData = (struct SetupData *)data;
643
650
struct ObjCBridgeMemo *memo = setupData->memo ;
644
- // Check that this always gets called with the same destType.
645
- assert ((memo->destType == nullptr ) || (memo->destType == setupData->destType ));
651
+ #if !NDEBUG
646
652
memo->destType = setupData->destType ;
647
- memo->destBridgeWitness = findBridgeWitness (memo->destType );
653
+ #endif
654
+ memo->destBridgeWitness = findBridgeWitness (setupData->destType );
648
655
if (memo->destBridgeWitness == nullptr ) {
649
656
memo->targetBridgedType = nullptr ;
650
657
memo->targetBridgedObjCClass = nullptr ;
651
658
} else {
652
659
memo->targetBridgedType = _getBridgedObjectiveCType (
653
- MetadataState::Complete, memo ->destType , memo->destBridgeWitness ).Value ;
660
+ MetadataState::Complete, setupData ->destType , memo->destBridgeWitness ).Value ;
654
661
assert (memo->targetBridgedType ->getKind () == MetadataKind::ObjCClassWrapper);
655
662
memo->targetBridgedObjCClass = memo->targetBridgedType ->getObjCClassObject ();
656
663
assert (memo->targetBridgedObjCClass != nullptr );
657
664
}
658
665
}, (void *)&setupData);
666
+
667
+ // Check that this always gets called with the same destType.
668
+ assert ((destType == this ->destType ) && " ObjC casting memo used inconsistently" );
669
+
659
670
// !! If bridging is not usable, stop here.
660
671
if (targetBridgedObjCClass == nullptr ) {
661
672
return DynamicCastResult::Failure;
0 commit comments