[Reflection] Cache the various DataQuery values.

We can end up querying the pointer size and similar things very frequently, which can be slow. These values don't change for any given reader, so call them once and cache the values locally instead.

rdar://150221008
This commit is contained in:
Mike Ash
2025-06-30 17:00:08 -04:00
parent d203591201
commit ca06ced1d2
4 changed files with 101 additions and 67 deletions

View File

@@ -565,16 +565,18 @@ std::unique_ptr<ReflectionContextHolder> makeReflectionContextForObjectFiles(
const std::vector<const ObjectFile *> &objectFiles, bool ObjCInterop) {
auto Reader = std::make_shared<ObjectMemoryReader>(objectFiles);
uint8_t pointerSize;
Reader->queryDataLayout(DataLayoutQueryType::DLQ_GetPointerSize, nullptr,
&pointerSize);
auto pointerSize = Reader->getPointerSize();
if (!pointerSize) {
fputs("unable to get target pointer size\n", stderr);
abort();
}
switch (pointerSize) {
switch (pointerSize.value()) {
case 4:
#define MAKE_CONTEXT(INTEROP, PTRSIZE) \
makeReflectionContextForMetadataReader< \
External<INTEROP<RuntimeTarget<PTRSIZE>>>>(std::move(Reader), \
pointerSize)
pointerSize.value())
#if SWIFT_OBJC_INTEROP
if (ObjCInterop)
return MAKE_CONTEXT(WithObjCInterop, 4);