From 052eacc3b9345ce68048e31657e518241c5b004d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 30 Sep 2015 11:51:06 -0400 Subject: [PATCH 1/4] symbols: Simplify GetSymbol --- src/common/symbols.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/common/symbols.cpp b/src/common/symbols.cpp index f23e51c9da..2115dc0625 100644 --- a/src/common/symbols.cpp +++ b/src/common/symbols.cpp @@ -29,17 +29,14 @@ namespace Symbols TSymbol GetSymbol(u32 _address) { - TSymbolsMap::iterator foundSymbolItr; - TSymbol symbol; + const auto iter = g_symbols.find(_address); - foundSymbolItr = g_symbols.find(_address); - if (foundSymbolItr != g_symbols.end()) - { - symbol = (*foundSymbolItr).second; - } + if (iter != g_symbols.end()) + return iter->second; - return symbol; + return {}; } + const std::string GetName(u32 _address) { return GetSymbol(_address).name; From 7e143d4422eebb108b6e1d9a67ed5e1b3b5c23da Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 30 Sep 2015 11:53:01 -0400 Subject: [PATCH 2/4] symbols: Directly initialize TSymbol members --- src/common/symbols.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/common/symbols.h b/src/common/symbols.h index 6b62b011ea..e9ddb532d2 100644 --- a/src/common/symbols.h +++ b/src/common/symbols.h @@ -12,15 +12,10 @@ struct TSymbol { - TSymbol() : - address(0), - size(0), - type(0) - {} - u32 address; + u32 address = 0; std::string name; - u32 size; - u32 type; + u32 size = 0; + u32 type = 0; }; typedef std::map TSymbolsMap; From 65d7a82db4d6b0236627baef1064a23695b12841 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 30 Sep 2015 11:54:44 -0400 Subject: [PATCH 3/4] symbols: Get rid of initial underscores in variable names --- src/common/symbols.cpp | 30 +++++++++++++++--------------- src/common/symbols.h | 10 +++++----- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/common/symbols.cpp b/src/common/symbols.cpp index 2115dc0625..0d7f0324a4 100644 --- a/src/common/symbols.cpp +++ b/src/common/symbols.cpp @@ -8,28 +8,28 @@ TSymbolsMap g_symbols; namespace Symbols { - bool HasSymbol(u32 _address) + bool HasSymbol(u32 address) { - return g_symbols.find(_address) != g_symbols.end(); + return g_symbols.find(address) != g_symbols.end(); } - void Add(u32 _address, const std::string& _name, u32 _size, u32 _type) + void Add(u32 address, const std::string& name, u32 size, u32 type) { - if (!HasSymbol(_address)) + if (!HasSymbol(address)) { TSymbol symbol; - symbol.address = _address; - symbol.name = _name; - symbol.size = _size; - symbol.type = _type; + symbol.address = address; + symbol.name = name; + symbol.size = size; + symbol.type = type; - g_symbols.insert(TSymbolsPair(_address, symbol)); + g_symbols.insert(TSymbolsPair(address, symbol)); } } - TSymbol GetSymbol(u32 _address) + TSymbol GetSymbol(u32 address) { - const auto iter = g_symbols.find(_address); + const auto iter = g_symbols.find(address); if (iter != g_symbols.end()) return iter->second; @@ -37,14 +37,14 @@ namespace Symbols return {}; } - const std::string GetName(u32 _address) + const std::string GetName(u32 address) { - return GetSymbol(_address).name; + return GetSymbol(address).name; } - void Remove(u32 _address) + void Remove(u32 address) { - g_symbols.erase(_address); + g_symbols.erase(address); } void Clear() diff --git a/src/common/symbols.h b/src/common/symbols.h index e9ddb532d2..5ed16009cc 100644 --- a/src/common/symbols.h +++ b/src/common/symbols.h @@ -23,12 +23,12 @@ typedef std::pair TSymbolsPair; namespace Symbols { - bool HasSymbol(u32 _address); + bool HasSymbol(u32 address); - void Add(u32 _address, const std::string& _name, u32 _size, u32 _type); - TSymbol GetSymbol(u32 _address); - const std::string GetName(u32 _address); - void Remove(u32 _address); + void Add(u32 address, const std::string& name, u32 size, u32 type); + TSymbol GetSymbol(u32 address); + const std::string GetName(u32 address); + void Remove(u32 address); void Clear(); } From 8cb2bc748d56cb0f0cb0f432e17fc6db73311696 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 30 Sep 2015 11:55:58 -0400 Subject: [PATCH 4/4] symbols: Replace an insert call with emplace --- src/common/symbols.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/symbols.cpp b/src/common/symbols.cpp index 0d7f0324a4..db83400438 100644 --- a/src/common/symbols.cpp +++ b/src/common/symbols.cpp @@ -23,7 +23,7 @@ namespace Symbols symbol.size = size; symbol.type = type; - g_symbols.insert(TSymbolsPair(address, symbol)); + g_symbols.emplace(address, symbol); } }