File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -206,11 +206,28 @@ struct _ObjectiveCBridgeableWitnessTable : WitnessTable {
206
206
extern " C" const ProtocolDescriptor
207
207
PROTOCOL_DESCR_SYM (s21_ObjectiveCBridgeable);
208
208
209
+ struct ObjCBridgeWitnessCacheEntry {
210
+ const Metadata *metadata;
211
+ const _ObjectiveCBridgeableWitnessTable *witness;
212
+ };
213
+
214
+ static std::atomic<ObjCBridgeWitnessCacheEntry> _objcBridgeWitnessCache = {};
215
+
209
216
static const _ObjectiveCBridgeableWitnessTable *
210
217
findBridgeWitness (const Metadata *T) {
218
+ auto cached = _objcBridgeWitnessCache.load (std::memory_order_relaxed);
219
+ if (cached.metadata == T) {
220
+ return cached.witness ;
221
+ }
211
222
auto w = swift_conformsToProtocolCommon (
212
223
T, &PROTOCOL_DESCR_SYM (s21_ObjectiveCBridgeable));
213
- return reinterpret_cast <const _ObjectiveCBridgeableWitnessTable *>(w);
224
+ auto result = reinterpret_cast <const _ObjectiveCBridgeableWitnessTable *>(w);
225
+ cached = {
226
+ .metadata = T,
227
+ .witness = result
228
+ };
229
+ _objcBridgeWitnessCache.store (cached, std::memory_order_relaxed);
230
+ return result;
214
231
}
215
232
216
233
// / Retrieve the bridged Objective-C type for the given type that
You can’t perform that action at this time.
0 commit comments