Skip to content

Commit 2efaeca

Browse files
committed
Avoid unconditionally calling into SwiftASTContext (NFC)
1 parent 4258a92 commit 2efaeca

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,8 +2506,14 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
25062506
child_byte_size, child_byte_offset, child_bitfield_bit_size,
25072507
child_bitfield_bit_offset, child_is_base_class,
25082508
child_is_deref_of_parent, valobj, language_flags));
2509-
auto ast_num_children = m_swift_ast_context->GetNumChildren(
2510-
ReconstructType(type), omit_empty_base_classes, exe_ctx);
2509+
llvm::Optional<unsigned> ast_num_children;
2510+
auto get_ast_num_children = [&]() {
2511+
if (ast_num_children)
2512+
return *ast_num_children;
2513+
ast_num_children = m_swift_ast_context->GetNumChildren(
2514+
ReconstructType(type), omit_empty_base_classes, exe_ctx);
2515+
return *ast_num_children;
2516+
};
25112517
auto impl = [&]() -> CompilerType {
25122518
ExecutionContextScope *exe_scope = nullptr;
25132519
if (exe_ctx)
@@ -2528,7 +2534,8 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
25282534
.endswith("sSo18NSNotificationNameaD"))
25292535
return GetTypeFromMangledTypename(ConstString("$sSo8NSStringCD"));
25302536
if (result.GetMangledTypeName().GetStringRef().count('$') > 1 &&
2531-
ast_num_children == runtime->GetNumChildren({this, type}, valobj))
2537+
get_ast_num_children() ==
2538+
runtime->GetNumChildren({this, type}, valobj))
25322539
// If available, prefer the AST for private types. Private
25332540
// identifiers are not ABI; the runtime returns anonymous private
25342541
// identifiers (using a '$' prefix) which cannot match identifiers
@@ -2634,7 +2641,7 @@ CompilerType TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
26342641
// Because the API deals out an index into a list of children we
26352642
// can't mix&match between the two typesystems if there is such a
26362643
// divergence. We'll need to replace all calls at once.
2637-
if (ast_num_children <
2644+
if (get_ast_num_children() <
26382645
runtime->GetNumChildren({this, type}, valobj).getValueOr(0))
26392646
return impl();
26402647

0 commit comments

Comments
 (0)