mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user