summaryrefslogtreecommitdiff
path: root/view/sharedcache/core/SharedCache.cpp
diff options
context:
space:
mode:
authorMark Rowe <mrowe@bdash.net.nz>2025-01-13 22:19:17 -0800
committerkat <kat@vector35.com>2025-01-15 09:49:10 -0500
commitb14f86d5373eb7a4a8a40c9a23c3a9faf2732eeb (patch)
treeba09ec39132d6c02b01f391867b44ed0872cda4e /view/sharedcache/core/SharedCache.cpp
parent0cea9333ac85d372cfa4be639e2fa4148153b3dc (diff)
[SharedCache] Avoid copying strings on each call to VM::MappingAtAddress
`PageMapping` was storing the path to the file it points within. This was causing unnecessary work within `VM::MappingAtAddress` as the `PageMapping`, and thus the path, is copied into the return value. This copying was more expensive than the map lookup. The file path is now stored within a `LazyMappedFileAccessor` class that wraps the `SelfAllocatingWeakPtr`. This means the path is still available via the `PageMapping`, but it does not need to be copied as often. This includes two additional improvements / optimizations while I was touching the code in question: 1. `MMappedFileAccessor::Open` no longer performs two hash lookups when a file accessor already exists. 2. `VM::MapPages` takes the path by const reference to avoid an unnecessary copy.
Diffstat (limited to 'view/sharedcache/core/SharedCache.cpp')
-rw-r--r--view/sharedcache/core/SharedCache.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp
index 33a4654d..0eb52c6a 100644
--- a/view/sharedcache/core/SharedCache.cpp
+++ b/view/sharedcache/core/SharedCache.cpp
@@ -780,7 +780,7 @@ void SharedCache::PerformInitialLoad()
if (imageHeader->linkeditPresent && vm->AddressIsMapped(imageHeader->linkeditSegment.vmaddr))
{
auto mapping = vm->MappingAtAddress(imageHeader->linkeditSegment.vmaddr);
- imageHeader->exportTriePath = mapping.first.filePath;
+ imageHeader->exportTriePath = mapping.first.fileAccessor->filePath();
}
MutableState().headers[start.second] = imageHeader.value();
CacheImage image;
@@ -3330,7 +3330,8 @@ extern "C"
images[i].mappings[j].vmAddress = sectionStart;
images[i].mappings[j].size = header.sections[j].size;
images[i].mappings[j].name = BNAllocString(header.sectionNames[j].c_str());
- images[i].mappings[j].filePath = BNAllocString(vm->MappingAtAddress(sectionStart).first.filePath.c_str());
+ auto fileAccessor = vm->MappingAtAddress(sectionStart).first.fileAccessor;
+ images[i].mappings[j].filePath = BNAllocStringWithLength(fileAccessor->filePath().data(), fileAccessor->filePath().length());
images[i].mappings[j].loaded = cache->object->IsMemoryMapped(sectionStart);
}
i++;