Skip to content

Commit

Permalink
Merge pull request #11813 from lioncash/insert
Browse files Browse the repository at this point in the history
PPCSymbolDB: Use emplace() where applicable
  • Loading branch information
AdmiralCurtiss committed May 9, 2023
2 parents c766b2f + 15d1ae3 commit 8c67083
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Source/Core/Common/SymbolDB.h
Expand Up @@ -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;
Expand Down
27 changes: 13 additions & 14 deletions Source/Core/Core/PowerPC/PPCSymbolDB.cpp
Expand Up @@ -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;
Expand All @@ -67,27 +67,26 @@ 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;
if (tf.type == Common::Symbol::Type::Function)
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)
{
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;
}
}

Expand Down

0 comments on commit 8c67083

Please sign in to comment.