@@ -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,26 +415,9 @@ 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 ) {
403
- if (BuiltinTypeDescriptor->Stride <= 0 )
404
- continue ;
405
- if (!BuiltinTypeDescriptor->hasMangledTypeName ())
406
- continue ;
407
-
408
- auto Alignment = BuiltinTypeDescriptor->getAlignment ();
409
- if (Alignment <= 0 )
410
- continue ;
411
- // Reject any alignment that's not a power of two.
412
- if (Alignment & (Alignment - 1 ))
413
- continue ;
414
-
415
- auto CandidateMangledName =
416
- readTypeRef (BuiltinTypeDescriptor, BuiltinTypeDescriptor->TypeName );
417
- if (!reflectionNameMatches (CandidateMangledName, MangledName))
418
- continue ;
419
- return BuiltinTypeDescriptor;
420
- }
418
+ if (const auto found = BuiltInTypeDescriptorCache.find (MangledName);
419
+ found != BuiltInTypeDescriptorCache.end ()) {
420
+ return found->second ;
421
421
}
422
422
423
423
return nullptr ;
0 commit comments