Turn loops into range-based form

and some things suggested by cppcheck and compiler warnings.
This commit is contained in:
Tillmann Karras
2014-02-12 16:00:34 +01:00
parent 2ff794d299
commit 404624bf0b
52 changed files with 199 additions and 230 deletions

View File

@ -206,23 +206,23 @@ void ARMXEmitter::ORI2R(ARMReg rd, ARMReg rs, u32 val, ARMReg scratch)
void ARMXEmitter::FlushLitPool()
{
for(std::vector<LiteralPool>::iterator it = currentLitPool.begin(); it != currentLitPool.end(); ++it) {
for(LiteralPool& pool : currentLitPool) {
// Search for duplicates
for(std::vector<LiteralPool>::iterator old_it = currentLitPool.begin(); old_it != it; ++old_it) {
if ((*old_it).val == (*it).val)
(*it).loc = (*old_it).loc;
for(LiteralPool& old_pool : currentLitPool) {
if (old_pool.val == pool.val)
pool.loc = old_pool.loc;
}
// Write the constant to Literal Pool
if (!(*it).loc)
if (!pool.loc)
{
(*it).loc = (s32)code;
Write32((*it).val);
pool.loc = (s32)code;
Write32(pool.val);
}
s32 offset = (*it).loc - (s32)(*it).ldr_address - 8;
s32 offset = pool.loc - (s32)pool.ldr_address - 8;
// Backpatch the LDR
*(u32*)(*it).ldr_address |= (offset >= 0) << 23 | abs(offset);
*(u32*)pool.ldr_address |= (offset >= 0) << 23 | abs(offset);
}
// TODO: Save a copy of previous pools in case they are still in range.
currentLitPool.clear();

View File

@ -8,11 +8,10 @@
#include "../Core/PowerPC/JitCommon/JitBase.h"
#include <sstream>
#include <algorithm>
bool BreakPoints::IsAddressBreakPoint(u32 _iAddress)
{
for (auto& bp : m_BreakPoints)
for (const TBreakPoint& bp : m_BreakPoints)
if (bp.iAddress == _iAddress)
return true;
return false;
@ -20,7 +19,7 @@ bool BreakPoints::IsAddressBreakPoint(u32 _iAddress)
bool BreakPoints::IsTempBreakPoint(u32 _iAddress)
{
for (auto& bp : m_BreakPoints)
for (const TBreakPoint& bp : m_BreakPoints)
if (bp.iAddress == _iAddress && bp.bTemporary)
return true;
return false;
@ -29,7 +28,7 @@ bool BreakPoints::IsTempBreakPoint(u32 _iAddress)
BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
{
TBreakPointsStr bps;
for (const auto& bp : m_BreakPoints)
for (const TBreakPoint& bp : m_BreakPoints)
{
if (!bp.bTemporary)
{
@ -44,7 +43,7 @@ BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
void BreakPoints::AddFromStrings(const TBreakPointsStr& bpstrs)
{
for (const auto& bpstr : bpstrs)
for (const std::string& bpstr : bpstrs)
{
TBreakPoint bp;
std::stringstream ss;
@ -84,7 +83,7 @@ void BreakPoints::Add(u32 em_address, bool temp)
void BreakPoints::Remove(u32 em_address)
{
for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
for (auto i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
{
if (i->iAddress == em_address)
{
@ -100,12 +99,10 @@ void BreakPoints::Clear()
{
if (jit)
{
std::for_each(m_BreakPoints.begin(), m_BreakPoints.end(),
[](const TBreakPoint& bp)
{
jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4);
}
);
for (const TBreakPoint& bp : m_BreakPoints)
{
jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4);
}
}
m_BreakPoints.clear();
@ -114,7 +111,7 @@ void BreakPoints::Clear()
MemChecks::TMemChecksStr MemChecks::GetStrings() const
{
TMemChecksStr mcs;
for (const auto& bp : m_MemChecks)
for (const TMemCheck& bp : m_MemChecks)
{
std::stringstream mc;
mc << std::hex << bp.StartAddress;
@ -129,7 +126,7 @@ MemChecks::TMemChecksStr MemChecks::GetStrings() const
void MemChecks::AddFromStrings(const TMemChecksStr& mcstrs)
{
for (const auto& mcstr : mcstrs)
for (const std::string& mcstr : mcstrs)
{
TMemCheck mc;
std::stringstream ss;
@ -156,7 +153,7 @@ void MemChecks::Add(const TMemCheck& _rMemoryCheck)
void MemChecks::Remove(u32 _Address)
{
for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
for (auto i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
{
if (i->StartAddress == _Address)
{
@ -168,7 +165,7 @@ void MemChecks::Remove(u32 _Address)
TMemCheck *MemChecks::GetMemCheck(u32 address)
{
for (auto& bp : m_MemChecks)
for (TMemCheck& bp : m_MemChecks)
{
if (bp.bRange)
{

View File

@ -192,7 +192,7 @@ std::vector<std::string> cdio_get_devices ()
for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j)
{
std::string drive = StringFromFormat(checklist[i].format, j);
if ( (is_cdrom(drive.c_str(), NULL)) > 0 )
if ( (is_cdrom(drive, NULL)) > 0 )
{
drives.push_back(std::move(drive));
}

View File

@ -117,9 +117,9 @@ public:
case MODE_WRITE:
case MODE_MEASURE:
case MODE_VERIFY:
for (auto itr = x.begin(); itr != x.end(); ++itr)
for (V& val : x)
{
Do(*itr);
Do(val);
}
break;
}

View File

@ -87,10 +87,9 @@ void IniFile::Section::Set(const std::string& key, const std::vector<std::string
{
std::string temp;
// Join the strings with ,
std::vector<std::string>::const_iterator it;
for (it = newValues.begin(); it != newValues.end(); ++it)
for (const std::string& value : newValues)
{
temp = (*it) + ",";
temp = value + ",";
}
// remove last ,
temp.resize(temp.length() - 1);
@ -210,7 +209,7 @@ bool IniFile::Section::Delete(const std::string& key)
const IniFile::Section* IniFile::GetSection(const std::string& sectionName) const
{
for (const auto& sect : sections)
for (const Section& sect : sections)
if (!strcasecmp(sect.name.c_str(), sectionName.c_str()))
return (&(sect));
return 0;
@ -218,7 +217,7 @@ const IniFile::Section* IniFile::GetSection(const std::string& sectionName) cons
IniFile::Section* IniFile::GetSection(const std::string& sectionName)
{
for (auto& sect : sections)
for (Section& sect : sections)
if (!strcasecmp(sect.name.c_str(), sectionName.c_str()))
return (&(sect));
return 0;
@ -240,7 +239,7 @@ bool IniFile::DeleteSection(const std::string& sectionName)
Section* s = GetSection(sectionName);
if (!s)
return false;
for (std::vector<Section>::iterator iter = sections.begin(); iter != sections.end(); ++iter)
for (auto iter = sections.begin(); iter != sections.end(); ++iter)
{
if (&(*iter) == s)
{
@ -399,21 +398,21 @@ bool IniFile::Save(const std::string& filename)
return false;
}
for (auto& section : sections)
for (const Section& section : sections)
{
if (section.keys_order.size() != 0 || section.lines.size() != 0)
out << "[" << section.name << "]" << std::endl;
if (section.keys_order.size() == 0)
{
for (auto s : section.lines)
for (const std::string& s : section.lines)
out << s << std::endl;
}
else
{
for (auto kvit = section.keys_order.begin(); kvit != section.keys_order.end(); ++kvit)
for (const std::string& kvit : section.keys_order)
{
auto pair = section.values.find(*kvit);
auto pair = section.values.find(kvit);
out << pair->first << " = " << pair->second << std::endl;
}
}

View File

@ -81,7 +81,7 @@ LogManager::LogManager()
m_consoleLog = new ConsoleListener();
m_debuggerLog = new DebuggerLogListener();
for (auto& container : m_Log)
for (LogContainer* container : m_Log)
{
container->SetEnable(true);
container->AddListener(m_fileLog);
@ -102,7 +102,7 @@ LogManager::~LogManager()
m_logManager->RemoveListener((LogTypes::LOG_TYPE)i, m_debuggerLog);
}
for (auto& container : m_Log)
for (LogContainer* container : m_Log)
delete container;
delete m_fileLog;
@ -168,10 +168,9 @@ void LogContainer::Trigger(LogTypes::LOG_LEVELS level, const char *msg)
{
std::lock_guard<std::mutex> lk(m_listeners_lock);
std::set<LogListener*>::const_iterator i;
for (i = m_listeners.begin(); i != m_listeners.end(); ++i)
for (LogListener* listener : m_listeners)
{
(*i)->Log(level, msg);
listener->Log(level, msg);
}
}

View File

@ -95,11 +95,6 @@ public:
const XFuncMap &Symbols() const {return functions;}
XFuncMap &AccessSymbols() {return functions;}
// deprecated
XFuncMap::iterator GetIterator() { return functions.begin(); }
XFuncMap::const_iterator GetConstIterator() { return functions.begin(); }
XFuncMap::iterator End() { return functions.end(); }
void Clear(const char *prefix = "");
void List();
void Index();

View File

@ -25,8 +25,7 @@ SysConf::~SysConf()
void SysConf::Clear()
{
for (std::vector<SSysConfEntry>::const_iterator i = m_Entries.begin();
i < m_Entries.end() - 1; i++)
for (auto i = m_Entries.begin(); i < m_Entries.end() - 1; ++i)
delete [] i->data;
m_Entries.clear();
}
@ -85,8 +84,7 @@ bool SysConf::LoadFromFileInternal(FILE *fh)
}
// Last offset is an invalid entry. We ignore it throughout this class
for (std::vector<SSysConfEntry>::iterator i = m_Entries.begin();
i < m_Entries.end() - 1; i++)
for (auto i = m_Entries.begin(); i < m_Entries.end() - 1; ++i)
{
SSysConfEntry& curEntry = *i;
f.Seek(curEntry.offset, SEEK_SET);
@ -300,7 +298,7 @@ void SysConf::GenerateSysConf()
items[26].data[0] = 0x01;
for (auto& item : items)
for (const SSysConfEntry& item : items)
m_Entries.push_back(item);
File::CreateFullPath(m_FilenameDefault);
@ -362,8 +360,7 @@ bool SysConf::SaveToFile(const char *filename)
{
File::IOFile f(filename, "r+b");
for (std::vector<SSysConfEntry>::iterator i = m_Entries.begin();
i < m_Entries.end() - 1; i++)
for (auto i = m_Entries.begin(); i < m_Entries.end() - 1; ++i)
{
// Seek to after the name of this entry
f.Seek(i->offset + i->nameLength + 1, SEEK_SET);

View File

@ -79,7 +79,7 @@ public:
}
std::vector<SSysConfEntry>::iterator index = m_Entries.begin();
for (; index < m_Entries.end() - 1; index++)
for (; index < m_Entries.end() - 1; ++index)
{
if (strcmp(index->name, sectionName) == 0)
break;
@ -102,7 +102,7 @@ public:
}
std::vector<SSysConfEntry>::iterator index = m_Entries.begin();
for (; index < m_Entries.end() - 1; index++)
for (; index < m_Entries.end() - 1; ++index)
{
if (strcmp(index->name, sectionName) == 0)
break;
@ -122,7 +122,7 @@ public:
return false;
std::vector<SSysConfEntry>::iterator index = m_Entries.begin();
for (; index < m_Entries.end() - 1; index++)
for (; index < m_Entries.end() - 1; ++index)
{
if (strcmp(index->name, sectionName) == 0)
break;
@ -143,7 +143,7 @@ public:
return false;
std::vector<SSysConfEntry>::iterator index = m_Entries.begin();
for (; index < m_Entries.end() - 1; index++)
for (; index < m_Entries.end() - 1; ++index)
{
if (strcmp(index->name, sectionName) == 0)
break;