@@ -201,22 +201,25 @@ TypeRefBuilder::getFieldTypeInfo(const TypeRef *TR) {
201201 if (Found != FieldTypeInfoCache.end ())
202202 return Found->second ;
203203
204- // On failure, fill out the cache with everything we know about.
205- std::vector<std::pair<std::string, const TypeRef *>> Fields;
206- for (auto &Info : ReflectionInfos) {
204+ // On failure, fill out the cache, ReflectionInfo by ReflectionInfo,
205+ // until we find the field desciptor we're looking for.
206+ while (FirstUnprocessedReflectionInfoIndex < ReflectionInfos.size ()) {
207+ auto &Info = ReflectionInfos[FirstUnprocessedReflectionInfoIndex];
207208 for (auto FD : Info.Field ) {
208209 if (!FD->hasMangledTypeName ())
209210 continue ;
210211 auto CandidateMangledName = readTypeRef (FD, FD->MangledTypeName );
211212 if (auto NormalizedName = normalizeReflectionName (CandidateMangledName))
212213 FieldTypeInfoCache[*NormalizedName] = FD;
213214 }
214- }
215215
216- // We've filled the cache with everything we know about now. Try the cache again.
217- Found = FieldTypeInfoCache.find (MangledName);
218- if (Found != FieldTypeInfoCache.end ())
219- return Found->second ;
216+ // Since we're done with the current ReflectionInfo, increment early in
217+ // case we get a cache hit.
218+ ++FirstUnprocessedReflectionInfoIndex;
219+ Found = FieldTypeInfoCache.find (MangledName);
220+ if (Found != FieldTypeInfoCache.end ())
221+ return Found->second ;
222+ }
220223
221224 return nullptr ;
222225}
0 commit comments