Skip to content

Commit 333e312

Browse files
Merge pull request #8086 from adrian-prantl/faster-unsafe-ptr
Avoid a costly SwiftASTContext initialization in SwiftUnsafeTypes for…
2 parents a69c247 + dad8cdc commit 333e312

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lldb/source/Plugins/Language/Swift/SwiftUnsafeTypes.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,18 @@ ExtractChildrenFromSwiftPointerValueObject(ValueObjectSP valobj_sp,
438438
const size_t num_children = unsafe_ptr.GetCount();
439439
const CompilerType element_type = unsafe_ptr.GetElementType();
440440

441+
// Performance optimization. Give up if this is a forward-declared
442+
// Clang type. In that case GetByteStride will attempt to fall back
443+
// to SwiftASTContext, which is generally correct because it could
444+
// be a type imported from an expression, but in this data formatter
445+
// the potential cost of triggering SwiftASTContext is not the right
446+
// trade-off.
447+
auto tss = element_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
448+
CompilerType clang_type;
449+
if (tss && tss->IsImportedType(element_type.GetOpaqueQualType(), &clang_type))
450+
if (!clang_type.IsCompleteType())
451+
return {};
452+
441453
auto stride = element_type.GetByteStride(process_sp.get());
442454
if (!stride)
443455
return {};

0 commit comments

Comments
 (0)