From b74c500aa9e5e7949ca46f42e0dc62e02136e259 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Mon, 14 Apr 2025 01:53:06 -0400 Subject: [SharedCache] Misc cleanup - Make `SharedCache::m_entries` a simple std::vector we never lookup based off the entry ID - Remove some old comments - Rename some old variables so that they are accurate - Fix compiler warnings - Remove some unneeded copying --- view/sharedcache/core/SharedCache.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'view/sharedcache/core/SharedCache.cpp') diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp index 55630da1..2eb885d4 100644 --- a/view/sharedcache/core/SharedCache.cpp +++ b/view/sharedcache/core/SharedCache.cpp @@ -8,9 +8,6 @@ using namespace BinaryNinja; -// The next id to use when calling Cache::AddEntry -static CacheEntryId nextId = 1; - std::pair> CacheSymbol::DemangledName(BinaryView &view) const { QualifiedName qname; @@ -230,13 +227,8 @@ void SharedCache::AddSymbols(std::vector&& symbols) m_symbols.insert({symbol.address, std::move(symbol)}); } -CacheEntryId SharedCache::AddEntry(CacheEntry entry) +void SharedCache::AddEntry(CacheEntry entry) { - // TODO: Maybe check to see if we already added the file? - // TODO: I doubt we will ever accidentally call this for the same entry... - // This is monotonically increasing so you can tell how many times we have called this function :) - CacheEntryId id = nextId++; - // Get the file accessor to associate with the virtual memory region. auto fileAccessor = FileAccessorCache::Global().Open(entry.GetFilePath()); @@ -253,8 +245,7 @@ CacheEntryId SharedCache::AddEntry(CacheEntry entry) } // We are done and can make the entry visible to the entire cache. - m_entries.insert({id, std::move(entry)}); - return id; + m_entries.push_back(std::move(entry)); } bool SharedCache::ProcessEntryImage(const std::string& path, const dyld_cache_image_info& info) @@ -330,7 +321,7 @@ void SharedCache::ProcessEntryImages(const CacheEntry& entry) // At this point all relevant mapping should be loaded in the virtual memory. void SharedCache::ProcessEntryRegions(const CacheEntry& entry) { - auto entryHeader = entry.GetHeader(); + const auto& entryHeader = entry.GetHeader(); // Collect pool addresses as non image memory regions. for (size_t i = 0; i < entryHeader.branchPoolsCount; i++) @@ -468,7 +459,7 @@ void SharedCache::ProcessSymbols() std::optional SharedCache::GetEntryContaining(const uint64_t address) const { - for (const auto& [_, entry] : m_entries) + for (const auto& entry : m_entries) { for (const auto& mapping : entry.GetMappings()) { @@ -482,7 +473,7 @@ std::optional SharedCache::GetEntryContaining(const uint64_t address std::optional SharedCache::GetEntryWithImage(const CacheImage& image) const { - for (const auto& [_, entry] : m_entries) + for (const auto& entry : m_entries) { for (const auto& [_, currentImage] : entry.GetImages()) { -- cgit v1.3.1