@@ -93,6 +93,14 @@ RemoteRef<char> TypeRefBuilder::readTypeRef(uint64_t remoteAddr) {
9393// / Load and normalize a mangled name so it can be matched with string equality.
9494llvm::Optional<std::string>
9595TypeRefBuilder::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+
96104 ScopedNodeFactoryCheckpoint checkpoint (this );
97105 // Remangle the reflection name to resolve symbolic references.
98106 if (auto node = demangleTypeRef (reflectionName,
@@ -102,18 +110,27 @@ TypeRefBuilder::normalizeReflectionName(RemoteRef<char> reflectionName) {
102110 case Node::Kind::ProtocolSymbolicReference:
103111 case Node::Kind::OpaqueTypeDescriptorSymbolicReference:
104112 // Symbolic references cannot be mangled, return a failure.
113+ NormalizedReflectionNameCache.insert (std::make_pair (
114+ reflectionNameRemoteAddress, llvm::Optional<std::string>()));
105115 return {};
106116 default :
107117 auto mangling = mangleNode (node);
108118 if (!mangling.isSuccess ()) {
119+ NormalizedReflectionNameCache.insert (std::make_pair (
120+ reflectionNameRemoteAddress, llvm::Optional<std::string>()));
109121 return {};
110122 }
123+ NormalizedReflectionNameCache.insert (
124+ std::make_pair (reflectionNameRemoteAddress, mangling.result ()));
111125 return std::move (mangling.result ());
112126 }
113127 }
114128
115129 // 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);
117134}
118135
119136// / Determine whether the given reflection protocol name matches.
@@ -398,8 +415,12 @@ TypeRefBuilder::getBuiltinTypeInfo(const TypeRef *TR) {
398415 else
399416 return nullptr ;
400417
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 ) {
403424 if (BuiltinTypeDescriptor->Stride <= 0 )
404425 continue ;
405426 if (!BuiltinTypeDescriptor->hasMangledTypeName ())
@@ -413,13 +434,21 @@ TypeRefBuilder::getBuiltinTypeInfo(const TypeRef *TR) {
413434 continue ;
414435
415436 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+ }
420444 }
421445 }
422446
447+ if (const auto found = BuiltInTypeDescriptorCache.find (MangledName);
448+ found != BuiltInTypeDescriptorCache.end ()) {
449+ return found->second ;
450+ }
451+
423452 return nullptr ;
424453}
425454
0 commit comments