@@ -211,15 +211,17 @@ static TypeSP LookupClangType(Module &m,
211
211
}
212
212
213
213
TypeSP TypeSystemSwiftTypeRef::LookupClangType (
214
- StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context) {
214
+ StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context,
215
+ ExecutionContext *exe_ctx) {
215
216
Module *m = GetModule ();
216
217
if (!m)
217
218
return {};
218
219
return ::LookupClangType (const_cast <Module &>(*m), decl_context);
219
220
}
220
221
221
222
TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType (
222
- StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context) {
223
+ StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context,
224
+ ExecutionContext *exe_ctx) {
223
225
// Check the cache first. Negative results are also cached.
224
226
TypeSP result;
225
227
ConstString name (name_ref);
@@ -229,15 +231,33 @@ TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType(
229
231
TargetSP target_sp = GetTargetWP ().lock ();
230
232
if (!target_sp)
231
233
return {};
232
- target_sp->GetImages ().ForEach ([&](const ModuleSP &m) -> bool {
234
+
235
+ ModuleSP cur_module;
236
+ if (exe_ctx)
237
+ if (StackFrame *frame = exe_ctx->GetFramePtr ())
238
+ cur_module =
239
+ frame->GetSymbolContext (lldb::eSymbolContextModule).module_sp ;
240
+
241
+ auto lookup = [&](const ModuleSP &m) -> bool {
242
+ // Already visited this.
243
+ if (m == cur_module)
244
+ return true ;
245
+
233
246
// Don't recursively call into LookupClangTypes() to avoid filling
234
247
// hundreds of image caches with negative results.
235
248
result = ::LookupClangType (const_cast <Module &>(*m), decl_context);
236
249
// Cache it in the expression context.
237
250
if (result)
238
251
m_clang_type_cache.Insert (name.AsCString (), result);
239
252
return !result;
240
- });
253
+ };
254
+
255
+ // Visit the current module first as a performance optimization heuristic.
256
+ if (cur_module)
257
+ if (!lookup (cur_module))
258
+ return result;
259
+
260
+ target_sp->GetImages ().ForEach (lookup);
241
261
return result;
242
262
}
243
263
0 commit comments