Some more optimizations and small code cleanups.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3066 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2014-11-10 16:13:28 +00:00
parent 1d1851dc3c
commit b863b55594
8 changed files with 38 additions and 51 deletions

View File

@ -128,13 +128,11 @@ void CheatManager::addPerFrame(Cheat* cheat, bool enable)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheatManager::addOneShot(const string& name, const string& code)
{
Cheat* cheat = createCheat(name, code);
if(!cheat)
return;
unique_ptr<Cheat> cheat(createCheat(name, code));
// Evaluate this cheat once, and then immediately delete it
cheat->evaluate();
delete cheat;
if(cheat)
cheat->evaluate();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -218,14 +216,14 @@ void CheatManager::parse(const string& cheats)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CheatManager::enable(const string& code, bool enable)
{
for(unsigned int i = 0; i < myCheatList.size(); i++)
for(const auto& cheat: myCheatList)
{
if(myCheatList[i]->code() == code)
if(cheat->code() == code)
{
if(enable)
myCheatList[i]->enable();
cheat->enable();
else
myCheatList[i]->disable();
cheat->disable();
break;
}
}
@ -327,7 +325,7 @@ void CheatManager::saveCheats(const string& md5sum)
// Only update the list if absolutely necessary
if(changed)
{
CheatCodeMap::iterator iter = myCheatMap.find(md5sum);
auto iter = myCheatMap.find(md5sum);
// Erase old entry and add a new one only if it's changed
if(iter != myCheatMap.end())
@ -350,16 +348,16 @@ void CheatManager::clear()
// the following loop
myPerFrameList.clear();
for(unsigned int i = 0; i < myCheatList.size(); i++)
delete myCheatList[i];
for(auto cheat: myCheatList)
delete cheat;
myCheatList.clear();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool CheatManager::isValidCode(const string& code) const
{
for(unsigned int i = 0; i < code.size(); i++)
if(!isxdigit(code[i]))
for(auto c: code)
if(!isxdigit(c))
return false;
uInt32 length = (uInt32)code.length();

View File

@ -28,7 +28,6 @@ class OSystem;
#include "bspf.hxx"
typedef vector<Cheat*> CheatList;
typedef map<string,string> CheatCodeMap;
/**
This class provides an interface for performing all cheat operations
@ -156,7 +155,7 @@ class CheatManager
CheatList myCheatList;
CheatList myPerFrameList;
CheatCodeMap myCheatMap;
map<string,string> myCheatMap;
string myCheatFile;
// This is set each time a new cheat/ROM is loaded, for later

View File

@ -326,15 +326,13 @@ void PNGLibrary::writeComments(png_structp png_ptr, png_infop info_ptr,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PNGLibrary::png_read_data(png_structp ctx, png_bytep area, png_size_t size)
{
ifstream* stream = (ifstream *) png_get_io_ptr(ctx);
stream->read((char *)area, size);
((ifstream *) png_get_io_ptr(ctx))->read((char *)area, size);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PNGLibrary::png_write_data(png_structp ctx, png_bytep area, png_size_t size)
{
ofstream* stream = (ofstream *) png_get_io_ptr(ctx);
stream->write((const char *)area, size);
((ofstream *) png_get_io_ptr(ctx))->write((const char *)area, size);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -268,7 +268,7 @@ bool CartDebug::disassemble(bool force)
if(bankChanged || !pcfound)
{
AddressList::const_iterator i;
for(i = addresses.begin(); i != addresses.end(); ++i)
for(auto i = addresses.begin(); i != addresses.end(); ++i)
{
if(PC < *i)
{
@ -537,11 +537,11 @@ bool CartDebug::addLabel(const string& label, uInt16 address)
bool CartDebug::removeLabel(const string& label)
{
// Only user-defined labels can be removed
LabelToAddr::iterator iter = myUserAddresses.find(label);
const auto& iter = myUserAddresses.find(label);
if(iter != myUserAddresses.end())
{
// Erase the address assigned to the label
AddrToLabel::iterator iter2 = myUserLabels.find(iter->second);
const auto& iter2 = myUserLabels.find(iter->second);
if(iter2 != myUserLabels.end())
myUserLabels.erase(iter2);
@ -612,8 +612,8 @@ bool CartDebug::getLabel(ostream& buf, uInt16 addr, bool isRead, int places) con
{
// RAM can use user-defined labels; otherwise we default to
// standard mnemonics
AddrToLabel::const_iterator iter;
if((iter = myUserLabels.find(addr)) != myUserLabels.end())
auto iter = myUserLabels.find(addr);
if(iter != myUserLabels.end())
{
buf << iter->second;
}
@ -634,8 +634,8 @@ bool CartDebug::getLabel(ostream& buf, uInt16 addr, bool isRead, int places) con
case ADDR_ROM:
{
// These addresses can never be in the system labels list
AddrToLabel::const_iterator iter;
if((iter = myUserLabels.find(addr)) != myUserLabels.end())
const auto& iter = myUserLabels.find(addr);
if(iter != myUserLabels.end())
{
buf << iter->second;
return true;

View File

@ -403,15 +403,15 @@ bool DebuggerParser::getArgs(const string& command, string& verb)
}
*/
for(int i = 0; i < argCount; i++) {
int err = YaccParser::parse(argStrings[i].c_str());
if(err) {
args.push_back(-1);
} else {
Expression* e = YaccParser::getResult();
args.push_back( e->evaluate() );
delete e;
for(int i = 0; i < argCount; i++)
{
if(!YaccParser::parse(argStrings[i].c_str()))
{
unique_ptr<Expression> expr(YaccParser::getResult());
args.push_back(expr->evaluate());
}
else
args.push_back(-1);
}
return true;
@ -422,7 +422,7 @@ bool DebuggerParser::validateArgs(int cmd)
{
// cerr << "entering validateArgs(" << cmd << ")" << endl;
bool required = commands[cmd].parmsRequired;
parameters *p = commands[cmd].parms;
parameters* p = commands[cmd].parms;
if(argCount == 0)
{

View File

@ -220,9 +220,8 @@ void EventHandler::poll(uInt64 time)
#endif
{
#ifdef CHEATCODE_SUPPORT
const CheatList& cheats = myOSystem.cheat().perFrame();
for(uInt32 i = 0; i < cheats.size(); i++)
cheats[i]->evaluate();
for(auto& cheat: myOSystem.cheat().perFrame())
cheat->evaluate();
#endif
// Handle continuous snapshots

View File

@ -43,10 +43,6 @@ System::System(const OSystem& osystem, M6502& m6502, M6532& m6532,
// Re-initialize random generator
randGenerator().initSeed();
// Allocate page table and dirty list
myPageAccessTable = new PageAccess[NUM_PAGES];
myPageIsDirtyTable = new bool[NUM_PAGES];
// Initialize page access table
PageAccess access(&myNullDevice, System::PA_READ);
for(int page = 0; page < NUM_PAGES; ++page)
@ -62,9 +58,6 @@ System::System(const OSystem& osystem, M6502& m6502, M6532& m6532,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
System::~System()
{
// Free my page access table and dirty list
delete[] myPageAccessTable;
delete[] myPageIsDirtyTable;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -218,7 +211,7 @@ void System::poke(uInt16 addr, uInt8 value)
uInt8 System::getAccessFlags(uInt16 addr) const
{
#ifdef DEBUGGER_SUPPORT
PageAccess& access = myPageAccessTable[(addr & ADDRESS_MASK) >> PAGE_SHIFT];
const PageAccess& access = myPageAccessTable[(addr & ADDRESS_MASK) >> PAGE_SHIFT];
if(access.codeAccessBase)
return *(access.codeAccessBase + (addr & PAGE_MASK));

View File

@ -396,11 +396,11 @@ class System : public Serializable
// Null device to use for page which are not installed
NullDevice myNullDevice;
// Pointer to a dynamically allocated array of PageAccess structures
PageAccess* myPageAccessTable;
// The list of PageAccess structures
PageAccess myPageAccessTable[NUM_PAGES];
// Pointer to a dynamically allocated array for dirty pages
bool* myPageIsDirtyTable;
// The list of dirty pages
bool myPageIsDirtyTable[NUM_PAGES];
// The current state of the Data Bus
uInt8 myDataBusState;