Updated std::map to use emplace instead of insert (optimization).

This commit is contained in:
Stephen Anthony 2017-06-09 14:50:11 -02:30
parent 3355183d03
commit 44ead7b926
8 changed files with 17 additions and 19 deletions

View File

@ -244,7 +244,7 @@ void CheatManager::loadCheatDatabase()
md5 = line.substr(one + 1, two - one - 1); md5 = line.substr(one + 1, two - one - 1);
cheat = line.substr(three + 1, four - three - 1); cheat = line.substr(three + 1, four - three - 1);
myCheatMap.insert(make_pair(md5, cheat)); myCheatMap.emplace(md5, cheat);
} }
myListIsDirty = false; myListIsDirty = false;
@ -315,7 +315,7 @@ void CheatManager::saveCheats(const string& md5sum)
// Add new entry only if there are any cheats defined // Add new entry only if there are any cheats defined
if(cheats.str() != "") if(cheats.str() != "")
myCheatMap.insert(make_pair(md5sum, cheats.str())); myCheatMap.emplace(md5sum, cheats.str());
} }
// Update the dirty flag // Update the dirty flag

View File

@ -71,7 +71,6 @@ using std::make_ptr;
using std::make_shared; using std::make_shared;
using std::array; using std::array;
using std::vector; using std::vector;
using std::make_pair;
using std::runtime_error; using std::runtime_error;
using std::memcpy; using std::memcpy;

View File

@ -78,24 +78,24 @@ CartDebug::CartDebug(Debugger& dbg, Console& console, const OSystem& osystem)
for(uInt16 addr = 0x00; addr <= 0x0F; ++addr) for(uInt16 addr = 0x00; addr <= 0x0F; ++addr)
{ {
if(ourTIAMnemonicR[addr]) if(ourTIAMnemonicR[addr])
mySystemAddresses.insert(make_pair(ourTIAMnemonicR[addr], addr)); mySystemAddresses.emplace(ourTIAMnemonicR[addr], addr);
myReserved.TIARead[addr] = false; myReserved.TIARead[addr] = false;
} }
for(uInt16 addr = 0x00; addr <= 0x3F; ++addr) for(uInt16 addr = 0x00; addr <= 0x3F; ++addr)
{ {
if(ourTIAMnemonicW[addr]) if(ourTIAMnemonicW[addr])
mySystemAddresses.insert(make_pair(ourTIAMnemonicW[addr], addr)); mySystemAddresses.emplace(ourTIAMnemonicW[addr], addr);
myReserved.TIAWrite[addr] = false; myReserved.TIAWrite[addr] = false;
} }
for(uInt16 addr = 0x280; addr <= 0x297; ++addr) for(uInt16 addr = 0x280; addr <= 0x297; ++addr)
{ {
if(ourIOMnemonic[addr-0x280]) if(ourIOMnemonic[addr-0x280])
mySystemAddresses.insert(make_pair(ourIOMnemonic[addr-0x280], addr)); mySystemAddresses.emplace(ourIOMnemonic[addr-0x280], addr);
myReserved.IOReadWrite[addr-0x280] = false; myReserved.IOReadWrite[addr-0x280] = false;
} }
for(uInt16 addr = 0x80; addr <= 0xFF; ++addr) 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; myReserved.ZPRAM[addr-0x80] = false;
} }
@ -312,7 +312,7 @@ bool CartDebug::fillDisassemblyList(BankInfo& info, uInt16 search)
if(tag.type != CartDebug::ROW) if(tag.type != CartDebug::ROW)
{ {
// Create a mapping from addresses to line numbers // Create a mapping from addresses to line numbers
myAddrToLineList.insert(make_pair(address, i)); myAddrToLineList.emplace(address, i);
// Did we find the search value? // Did we find the search value?
if(address == (search & 0xFFF)) if(address == (search & 0xFFF))
@ -517,8 +517,8 @@ bool CartDebug::addLabel(const string& label, uInt16 address)
return false; return false;
default: default:
removeLabel(label); removeLabel(label);
myUserAddresses.insert(make_pair(label, address)); myUserAddresses.emplace(label, address);
myUserLabels.insert(make_pair(address, label)); myUserLabels.emplace(address, label);
myLabelLength = std::max(myLabelLength, uInt16(label.size())); myLabelLength = std::max(myLabelLength, uInt16(label.size()));
mySystem.setDirtyPage(address); mySystem.setDirtyPage(address);
return true; return true;
@ -728,7 +728,7 @@ string CartDebug::loadListFile()
char eq = '\0'; char eq = '\0';
buf >> hex >> xx >> hex >> yy >> line >> eq; buf >> hex >> xx >> hex >> yy >> line >> eq;
if(xx >= 0 && yy >= 0 && eq == '=') if(xx >= 0 && yy >= 0 && eq == '=')
myUserCLabels.insert(make_pair(xx*256+yy, line)); myUserCLabels.emplace(xx*256+yy, line);
} }
} }
} }

View File

@ -512,8 +512,8 @@ void Debugger::setQuitState()
bool Debugger::addFunction(const string& name, const string& definition, bool Debugger::addFunction(const string& name, const string& definition,
Expression* exp, bool builtin) Expression* exp, bool builtin)
{ {
myFunctions.insert(make_pair(name, unique_ptr<Expression>(exp))); myFunctions.emplace(name, unique_ptr<Expression>(exp));
myFunctionDefs.insert(make_pair(name, definition)); myFunctionDefs.emplace(name, definition);
return true; return true;
} }

View File

@ -211,7 +211,7 @@ DiStella::DiStella(const CartDebug& dbg, CartDebug::DisassemblyList& list,
{ {
reservedLabel.str(""); reservedLabel.str("");
reservedLabel << "L" << Base::HEX4 << (k+myOffset); reservedLabel << "L" << Base::HEX4 << (k+myOffset);
myReserved.Label.insert(make_pair(k+myOffset, reservedLabel.str())); myReserved.Label.emplace(k+myOffset, reservedLabel.str());
} }
} }
} }

View File

@ -117,7 +117,6 @@ bool CartridgeFE::bankChanged()
return Cartridge::bankChanged(); return Cartridge::bankChanged();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CartridgeFE::patch(uInt16 address, uInt8 value) bool CartridgeFE::patch(uInt16 address, uInt8 value)
{ {

View File

@ -250,7 +250,7 @@ EventHandler::JoystickHandler::JoystickHandler(OSystem& system)
if(joyname.length() != 0) if(joyname.length() != 0)
{ {
StickInfo info(joymap); 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 else // adding for the first time
{ {
StickInfo info("", stick); 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, kEmulationMode);
setStickDefaultMapping(stick->ID, Event::NoType, kMenuMode); setStickDefaultMapping(stick->ID, Event::NoType, kMenuMode);
} }

View File

@ -169,7 +169,7 @@ void PropertiesSet::insert(const Properties& properties, bool save)
{ {
// Remove old item and insert again // Remove old item and insert again
list.erase(ret.first); 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) if(DefProps[i][p][0] != 0)
properties.set(PropertyType(p), DefProps[i][p]); 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 // Now, print the resulting list