From a14d8003f423b13b3c2cae3e1740f41957a4bae6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 2 May 2023 15:41:01 -0400 Subject: [PATCH 1/2] PPCSymbolDB: Use emplace() where applicable Avoids default constructing an entry in the map that just gets immediately overwritten. Also gets rid of some redundant map lookups. --- Source/Core/Core/PowerPC/PPCSymbolDB.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp index fea9a0b586..a231701cf1 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp @@ -44,8 +44,8 @@ Common::Symbol* PPCSymbolDB::AddFunction(const Core::CPUThreadGuard& guard, u32 if (!PPCAnalyst::AnalyzeFunction(guard, start_addr, symbol)) return nullptr; - m_functions[start_addr] = std::move(symbol); - Common::Symbol* ptr = &m_functions[start_addr]; + const auto insert = m_functions.emplace(start_addr, std::move(symbol)); + Common::Symbol* ptr = &insert.first->second; ptr->type = Common::Symbol::Type::Function; m_checksum_to_function[ptr->hash].insert(ptr); return ptr; @@ -71,23 +71,25 @@ void PPCSymbolDB::AddKnownSymbol(const Core::CPUThreadGuard& guard, u32 startAdd tf.Rename(name); tf.type = type; tf.address = startAddr; - if (tf.type == Common::Symbol::Type::Function) + + auto& new_symbol = m_functions.emplace(startAddr, std::move(tf)).first->second; + + if (new_symbol.type == Common::Symbol::Type::Function) { - PPCAnalyst::AnalyzeFunction(guard, startAddr, tf, size); + PPCAnalyst::AnalyzeFunction(guard, startAddr, new_symbol, size); // Do not truncate symbol when a size is expected - if (size != 0 && tf.size != size) + if (size != 0 && new_symbol.size != size) { WARN_LOG_FMT(SYMBOLS, "Analysed symbol ({}) size mismatch, {} expected but {} computed", - name, size, tf.size); - tf.size = size; + name, size, new_symbol.size); + new_symbol.size = size; } - m_checksum_to_function[tf.hash].insert(&m_functions[startAddr]); + m_checksum_to_function[new_symbol.hash].insert(&new_symbol); } else { - tf.size = size; + new_symbol.size = size; } - m_functions[startAddr] = tf; } } From 15d1ae3a8abf93e18a524e26ffe87459c0511d16 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 2 May 2023 16:04:45 -0400 Subject: [PATCH 2/2] SymbolDB: Add constructors to Symbol Allows for much more convenient in-place construction. --- Source/Core/Common/SymbolDB.h | 3 +++ Source/Core/Core/PowerPC/PPCSymbolDB.cpp | 9 +++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/Common/SymbolDB.h b/Source/Core/Common/SymbolDB.h index c7efa0212a..e3882637cb 100644 --- a/Source/Core/Common/SymbolDB.h +++ b/Source/Core/Common/SymbolDB.h @@ -37,6 +37,9 @@ struct Symbol Data, }; + Symbol() = default; + explicit Symbol(const std::string& name) { Rename(name); } + void Rename(const std::string& symbol_name); std::string name; diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp index a231701cf1..7b96c29fad 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp @@ -67,12 +67,9 @@ void PPCSymbolDB::AddKnownSymbol(const Core::CPUThreadGuard& guard, u32 startAdd else { // new symbol. run analyze. - Common::Symbol tf; - tf.Rename(name); - tf.type = type; - tf.address = startAddr; - - auto& new_symbol = m_functions.emplace(startAddr, std::move(tf)).first->second; + auto& new_symbol = m_functions.emplace(startAddr, name).first->second; + new_symbol.type = type; + new_symbol.address = startAddr; if (new_symbol.type == Common::Symbol::Type::Function) {