@@ -93,6 +93,14 @@ RemoteRef<char> TypeRefBuilder::readTypeRef(uint64_t remoteAddr) {
93
93
// / Load and normalize a mangled name so it can be matched with string equality.
94
94
llvm::Optional<std::string>
95
95
TypeRefBuilder::normalizeReflectionName (RemoteRef<char > reflectionName) {
96
+ const auto reflectionNameRemoteAddress = reflectionName.getAddressData ();
97
+
98
+ if (const auto found =
99
+ NormalizedReflectionNameCache.find (reflectionNameRemoteAddress);
100
+ found != NormalizedReflectionNameCache.end ()) {
101
+ return found->second ;
102
+ }
103
+
96
104
ScopedNodeFactoryCheckpoint checkpoint (this );
97
105
// Remangle the reflection name to resolve symbolic references.
98
106
if (auto node = demangleTypeRef (reflectionName,
@@ -102,18 +110,27 @@ TypeRefBuilder::normalizeReflectionName(RemoteRef<char> reflectionName) {
102
110
case Node::Kind::ProtocolSymbolicReference:
103
111
case Node::Kind::OpaqueTypeDescriptorSymbolicReference:
104
112
// Symbolic references cannot be mangled, return a failure.
113
+ NormalizedReflectionNameCache.insert (std::make_pair (
114
+ reflectionNameRemoteAddress, llvm::Optional<std::string>()));
105
115
return {};
106
116
default :
107
117
auto mangling = mangleNode (node);
108
118
if (!mangling.isSuccess ()) {
119
+ NormalizedReflectionNameCache.insert (std::make_pair (
120
+ reflectionNameRemoteAddress, llvm::Optional<std::string>()));
109
121
return {};
110
122
}
123
+ NormalizedReflectionNameCache.insert (
124
+ std::make_pair (reflectionNameRemoteAddress, mangling.result ()));
111
125
return std::move (mangling.result ());
112
126
}
113
127
}
114
128
115
129
// Fall back to the raw string.
116
- return getTypeRefString (reflectionName).str ();
130
+ const auto manglingResult = getTypeRefString (reflectionName).str ();
131
+ NormalizedReflectionNameCache.insert (
132
+ std::make_pair (reflectionNameRemoteAddress, manglingResult));
133
+ return std::move (manglingResult);
117
134
}
118
135
119
136
// / Determine whether the given reflection protocol name matches.
@@ -398,8 +415,12 @@ TypeRefBuilder::getBuiltinTypeInfo(const TypeRef *TR) {
398
415
else
399
416
return nullptr ;
400
417
401
- for (auto Info : ReflectionInfos) {
402
- for (auto BuiltinTypeDescriptor : Info.Builtin ) {
418
+ for (; NormalizedReflectionNameCacheLastReflectionInfoCache <
419
+ ReflectionInfos.size ();
420
+ NormalizedReflectionNameCacheLastReflectionInfoCache++) {
421
+ for (auto BuiltinTypeDescriptor :
422
+ ReflectionInfos[NormalizedReflectionNameCacheLastReflectionInfoCache]
423
+ .Builtin ) {
403
424
if (BuiltinTypeDescriptor->Stride <= 0 )
404
425
continue ;
405
426
if (!BuiltinTypeDescriptor->hasMangledTypeName ())
@@ -413,13 +434,21 @@ TypeRefBuilder::getBuiltinTypeInfo(const TypeRef *TR) {
413
434
continue ;
414
435
415
436
auto CandidateMangledName =
416
- readTypeRef (BuiltinTypeDescriptor, BuiltinTypeDescriptor->TypeName );
417
- if (!reflectionNameMatches (CandidateMangledName, MangledName))
418
- continue ;
419
- return BuiltinTypeDescriptor;
437
+ readTypeRef (BuiltinTypeDescriptor, BuiltinTypeDescriptor->TypeName );
438
+ auto CandidateNormalizedName =
439
+ normalizeReflectionName (CandidateMangledName);
440
+ if (CandidateNormalizedName) {
441
+ BuiltInTypeDescriptorCache.insert (
442
+ std::make_pair (*CandidateNormalizedName, BuiltinTypeDescriptor));
443
+ }
420
444
}
421
445
}
422
446
447
+ if (const auto found = BuiltInTypeDescriptorCache.find (MangledName);
448
+ found != BuiltInTypeDescriptorCache.end ()) {
449
+ return found->second ;
450
+ }
451
+
423
452
return nullptr ;
424
453
}
425
454
0 commit comments