From 44ead7b9269c46e5846e5d0f55f8e4ad03fe1914 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Fri, 9 Jun 2017 14:50:11 -0230 Subject: [PATCH] Updated std::map to use emplace instead of insert (optimization). --- src/cheat/CheatManager.cxx | 4 ++-- src/common/bspf.hxx | 1 - src/debugger/CartDebug.cxx | 16 ++++++++-------- src/debugger/Debugger.cxx | 4 ++-- src/debugger/DiStella.cxx | 2 +- src/emucore/CartFE.cxx | 1 - src/emucore/EventJoyHandler.cxx | 4 ++-- src/emucore/PropsSet.cxx | 4 ++-- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/cheat/CheatManager.cxx b/src/cheat/CheatManager.cxx index 0b8b85ac6..1c94aaca4 100644 --- a/src/cheat/CheatManager.cxx +++ b/src/cheat/CheatManager.cxx @@ -244,7 +244,7 @@ void CheatManager::loadCheatDatabase() md5 = line.substr(one + 1, two - one - 1); cheat = line.substr(three + 1, four - three - 1); - myCheatMap.insert(make_pair(md5, cheat)); + myCheatMap.emplace(md5, cheat); } myListIsDirty = false; @@ -315,7 +315,7 @@ void CheatManager::saveCheats(const string& md5sum) // Add new entry only if there are any cheats defined if(cheats.str() != "") - myCheatMap.insert(make_pair(md5sum, cheats.str())); + myCheatMap.emplace(md5sum, cheats.str()); } // Update the dirty flag diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index ec3d4d40c..a7b441b79 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -71,7 +71,6 @@ using std::make_ptr; using std::make_shared; using std::array; using std::vector; -using std::make_pair; using std::runtime_error; using std::memcpy; diff --git a/src/debugger/CartDebug.cxx b/src/debugger/CartDebug.cxx index 8a016d091..0ddc9a3ef 100644 --- a/src/debugger/CartDebug.cxx +++ b/src/debugger/CartDebug.cxx @@ -78,24 +78,24 @@ CartDebug::CartDebug(Debugger& dbg, Console& console, const OSystem& osystem) for(uInt16 addr = 0x00; addr <= 0x0F; ++addr) { if(ourTIAMnemonicR[addr]) - mySystemAddresses.insert(make_pair(ourTIAMnemonicR[addr], addr)); + mySystemAddresses.emplace(ourTIAMnemonicR[addr], addr); myReserved.TIARead[addr] = false; } for(uInt16 addr = 0x00; addr <= 0x3F; ++addr) { if(ourTIAMnemonicW[addr]) - mySystemAddresses.insert(make_pair(ourTIAMnemonicW[addr], addr)); + mySystemAddresses.emplace(ourTIAMnemonicW[addr], addr); myReserved.TIAWrite[addr] = false; } for(uInt16 addr = 0x280; addr <= 0x297; ++addr) { if(ourIOMnemonic[addr-0x280]) - mySystemAddresses.insert(make_pair(ourIOMnemonic[addr-0x280], addr)); + mySystemAddresses.emplace(ourIOMnemonic[addr-0x280], addr); myReserved.IOReadWrite[addr-0x280] = false; } for(uInt16 addr = 0x80; addr <= 0xFF; ++addr) { - mySystemAddresses.insert(make_pair(ourZPMnemonic[addr-0x80], addr)); + mySystemAddresses.emplace(ourZPMnemonic[addr-0x80], addr); myReserved.ZPRAM[addr-0x80] = false; } @@ -312,7 +312,7 @@ bool CartDebug::fillDisassemblyList(BankInfo& info, uInt16 search) if(tag.type != CartDebug::ROW) { // Create a mapping from addresses to line numbers - myAddrToLineList.insert(make_pair(address, i)); + myAddrToLineList.emplace(address, i); // Did we find the search value? if(address == (search & 0xFFF)) @@ -517,8 +517,8 @@ bool CartDebug::addLabel(const string& label, uInt16 address) return false; default: removeLabel(label); - myUserAddresses.insert(make_pair(label, address)); - myUserLabels.insert(make_pair(address, label)); + myUserAddresses.emplace(label, address); + myUserLabels.emplace(address, label); myLabelLength = std::max(myLabelLength, uInt16(label.size())); mySystem.setDirtyPage(address); return true; @@ -728,7 +728,7 @@ string CartDebug::loadListFile() char eq = '\0'; buf >> hex >> xx >> hex >> yy >> line >> eq; if(xx >= 0 && yy >= 0 && eq == '=') - myUserCLabels.insert(make_pair(xx*256+yy, line)); + myUserCLabels.emplace(xx*256+yy, line); } } } diff --git a/src/debugger/Debugger.cxx b/src/debugger/Debugger.cxx index 57804b9ed..dfa3e8806 100644 --- a/src/debugger/Debugger.cxx +++ b/src/debugger/Debugger.cxx @@ -512,8 +512,8 @@ void Debugger::setQuitState() bool Debugger::addFunction(const string& name, const string& definition, Expression* exp, bool builtin) { - myFunctions.insert(make_pair(name, unique_ptr(exp))); - myFunctionDefs.insert(make_pair(name, definition)); + myFunctions.emplace(name, unique_ptr(exp)); + myFunctionDefs.emplace(name, definition); return true; } diff --git a/src/debugger/DiStella.cxx b/src/debugger/DiStella.cxx index 5c33f342a..81ef5f64b 100644 --- a/src/debugger/DiStella.cxx +++ b/src/debugger/DiStella.cxx @@ -211,7 +211,7 @@ DiStella::DiStella(const CartDebug& dbg, CartDebug::DisassemblyList& list, { reservedLabel.str(""); reservedLabel << "L" << Base::HEX4 << (k+myOffset); - myReserved.Label.insert(make_pair(k+myOffset, reservedLabel.str())); + myReserved.Label.emplace(k+myOffset, reservedLabel.str()); } } } diff --git a/src/emucore/CartFE.cxx b/src/emucore/CartFE.cxx index b3db7e6d6..cf56843d4 100644 --- a/src/emucore/CartFE.cxx +++ b/src/emucore/CartFE.cxx @@ -117,7 +117,6 @@ bool CartridgeFE::bankChanged() return Cartridge::bankChanged(); } - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeFE::patch(uInt16 address, uInt8 value) { diff --git a/src/emucore/EventJoyHandler.cxx b/src/emucore/EventJoyHandler.cxx index 0ce502180..7cc2dd213 100644 --- a/src/emucore/EventJoyHandler.cxx +++ b/src/emucore/EventJoyHandler.cxx @@ -250,7 +250,7 @@ EventHandler::JoystickHandler::JoystickHandler(OSystem& system) if(joyname.length() != 0) { StickInfo info(joymap); - myDatabase.insert(make_pair(joyname, info)); + myDatabase.emplace(joyname, info); } } } @@ -343,7 +343,7 @@ bool EventHandler::JoystickHandler::add(StellaJoystick* stick) else // adding for the first time { StickInfo info("", stick); - myDatabase.insert(make_pair(stick->name, info)); + myDatabase.emplace(stick->name, info); setStickDefaultMapping(stick->ID, Event::NoType, kEmulationMode); setStickDefaultMapping(stick->ID, Event::NoType, kMenuMode); } diff --git a/src/emucore/PropsSet.cxx b/src/emucore/PropsSet.cxx index 433a98592..d9393645e 100644 --- a/src/emucore/PropsSet.cxx +++ b/src/emucore/PropsSet.cxx @@ -169,7 +169,7 @@ void PropertiesSet::insert(const Properties& properties, bool save) { // Remove old item and insert again list.erase(ret.first); - list.insert(make_pair(md5, properties)); + list.emplace(md5, properties); } } @@ -205,7 +205,7 @@ void PropertiesSet::print() const if(DefProps[i][p][0] != 0) properties.set(PropertyType(p), DefProps[i][p]); - list.insert(make_pair(DefProps[i][Cartridge_MD5], properties)); + list.emplace(DefProps[i][Cartridge_MD5], properties); } // Now, print the resulting list