@@ -64,27 +64,6 @@ static Demangler getDemanglerForRuntimeTypeResolution() {
64
64
return dem;
65
65
}
66
66
67
- template <typename T> struct DescriptorCacheEntry {
68
- private:
69
- std::string Name;
70
- const T *Description;
71
-
72
- public:
73
- DescriptorCacheEntry (const llvm::StringRef name, const T *description)
74
- : Name(name.str()), Description(description) {}
75
-
76
- const T *getDescription () { return Description; }
77
-
78
- int compareWithKey (llvm::StringRef aName) const {
79
- return aName.compare (Name);
80
- }
81
-
82
- template <class ... Args>
83
- static size_t getExtraAllocationSize (Args &&... ignored) {
84
- return 0 ;
85
- }
86
- };
87
-
88
67
#pragma mark Nominal type descriptor cache
89
68
// Type Metadata Cache.
90
69
@@ -333,8 +312,30 @@ namespace {
333
312
}
334
313
};
335
314
315
+ struct ProtocolDescriptorCacheEntry {
316
+ private:
317
+ std::string Name;
318
+ const ProtocolDescriptor *Description;
319
+
320
+ public:
321
+ ProtocolDescriptorCacheEntry (const llvm::StringRef name,
322
+ const ProtocolDescriptor *description)
323
+ : Name(name.str()), Description(description) {}
324
+
325
+ const ProtocolDescriptor *getDescription () { return Description; }
326
+
327
+ int compareWithKey (llvm::StringRef aName) const {
328
+ return aName.compare (Name);
329
+ }
330
+
331
+ template <class ... T>
332
+ static size_t getExtraAllocationSize (T &&... ignored) {
333
+ return 0 ;
334
+ }
335
+ };
336
+
336
337
struct ProtocolMetadataState {
337
- ConcurrentMap<DescriptorCacheEntry<ProtocolDescriptor> > ProtocolCache;
338
+ ConcurrentMap<ProtocolDescriptorCacheEntry > ProtocolCache;
338
339
std::vector<ProtocolSection> SectionsToScan;
339
340
Mutex SectionsToScanLock;
340
341
@@ -425,19 +426,22 @@ _findProtocolDescriptor(llvm::StringRef mangledName) {
425
426
426
427
#pragma mark Type field descriptor cache
427
428
namespace {
428
- template < typename T> struct FieldDescriptorCacheEntry {
429
+ struct FieldDescriptorCacheEntry {
429
430
private:
430
- const Metadata *Base ;
431
- const T *Description;
431
+ const Metadata *Type ;
432
+ const FieldDescriptor *Description;
432
433
433
434
public:
434
- FieldDescriptorCacheEntry (const Metadata *Base, const T *description)
435
- : Base(Base), Description(description) {}
435
+ FieldDescriptorCacheEntry (const Metadata *type,
436
+ const FieldDescriptor *description)
437
+ : Type(type), Description(description) {}
436
438
437
- const T *getDescription () { return Description; }
439
+ const FieldDescriptor *getDescription () { return Description; }
438
440
439
441
int compareWithKey (const Metadata *other) const {
440
- return Base == other;
442
+ auto a = (uintptr_t )Type;
443
+ auto b = (uintptr_t )other;
444
+ return a == b ? 0 : (a < b ? -1 : 1 );
441
445
}
442
446
443
447
template <class ... Args>
@@ -477,7 +481,7 @@ class DynamicFieldSection {
477
481
};
478
482
479
483
struct FieldCacheState {
480
- ConcurrentMap<FieldDescriptorCacheEntry<FieldDescriptor> > FieldCache;
484
+ ConcurrentMap<FieldDescriptorCacheEntry> FieldCache;
481
485
482
486
Mutex SectionsLock;
483
487
std::vector<StaticFieldSection> StaticSections;
@@ -1122,12 +1126,10 @@ void swift::swift_getFieldAt(
1122
1126
1123
1127
1124
1128
// Fast path: If we already have field descriptor cached.
1125
- /*
1126
1129
if (auto Value = cache.FieldCache .find (base)) {
1127
1130
getFieldAt (*Value->getDescription ());
1128
1131
return ;
1129
1132
}
1130
- */
1131
1133
1132
1134
ScopedLock guard (cache.SectionsLock );
1133
1135
// Otherwise let's try to find it in one of the sections.
0 commit comments