Turn loops into range-based form

and some things suggested by cppcheck and compiler warnings.
This commit is contained in:
Tillmann Karras
2014-02-13 09:05:50 +01:00
parent 2ff794d299
commit 404624bf0b
52 changed files with 199 additions and 230 deletions
+9 -9
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();
+13 -16
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)
{
+1 -1
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));
}
+2 -2
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;
}
+9 -10
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;
}
}
+4 -5
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);
}
}
-5
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();
+4 -7
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);
+4 -4
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;
+3 -3
View File
@@ -673,9 +673,9 @@ void UpdateTitle()
if (ElapseTime == 0)
ElapseTime = 1;
float FPS = Common::AtomicLoad(DrawnFrame) * 1000.0 / ElapseTime;
float VPS = DrawnVideo * 1000.0 / ElapseTime;
float Speed = DrawnVideo * (100 * 1000.0) / (VideoInterface::TargetRefreshRate * ElapseTime);
float FPS = (float) (Common::AtomicLoad(DrawnFrame) * 1000.0 / ElapseTime);
float VPS = (float) (DrawnVideo * 1000.0 / ElapseTime);
float Speed = (float) (DrawnVideo * (100 * 1000.0) / (VideoInterface::TargetRefreshRate * ElapseTime));
// Settings are shown the same for both extended and summary info
std::string SSettings = StringFromFormat("%s %s | %s | %s", cpu_core_base->GetName(), _CoreParameter.bCPUThread ? "DC" : "SC",
+4 -5
View File
@@ -55,18 +55,17 @@ DSPDisassembler::~DSPDisassembler()
return;
int count = 0;
for (std::map<u16, int>::const_iterator iter = unk_opcodes.begin();
iter != unk_opcodes.end(); ++iter)
for (const auto& entry : unk_opcodes)
{
if (iter->second > 0)
if (entry.second > 0)
{
count++;
fprintf(uo.GetHandle(), "OP%04x\t%d", iter->first, iter->second);
fprintf(uo.GetHandle(), "OP%04x\t%d", entry.first, entry.second);
for (int j = 15; j >= 0; j--) // print op bits
{
if ((j & 0x3) == 3)
fprintf(uo.GetHandle(), "\tb");
fprintf(uo.GetHandle(), "%d", (iter->first >> j) & 0x1);
fprintf(uo.GetHandle(), "%d", (entry.first >> j) & 0x1);
}
fprintf(uo.GetHandle(), "\n");
}
+1 -1
View File
@@ -26,7 +26,7 @@ public:
u32 GetNextMail()
{
if (m_Mails.size())
if (!m_Mails.empty())
{
return m_Mails.front();
}
+1 -1
View File
@@ -77,7 +77,7 @@ bool GeckoSockServer::GetAvailableSock(sf::SocketTCP &sock_to_fill)
std::lock_guard<std::mutex> lk(connection_lock);
if (waiting_socks.size())
if (!waiting_socks.empty())
{
sock_to_fill = waiting_socks.front();
if (clientThread.joinable())
+1 -1
View File
@@ -56,7 +56,7 @@ bool GetAvailableSock(sf::SocketTCP& sock_to_fill)
std::lock_guard<std::mutex> lk(cs_gba);
if (waiting_socks.size())
if (!waiting_socks.empty())
{
sock_to_fill = waiting_socks.front();
waiting_socks.pop();
@@ -1257,7 +1257,7 @@ void Wiimote::DoState(PointerWrap& p)
if (p.mode == PointerWrap::MODE_READ)
{
//clear
while (m_read_requests.size())
while (!m_read_requests.empty())
m_read_requests.pop();
p.Do(size);
@@ -252,7 +252,7 @@ void Wiimote::Reset()
memset(m_shake_step, 0, sizeof(m_shake_step));
// clear read request queue
while (m_read_requests.size())
while (!m_read_requests.empty())
{
delete[] m_read_requests.front().data;
m_read_requests.pop();
@@ -351,7 +351,7 @@ bool Wiimote::Step()
}
// check if there is a read data request
if (m_read_requests.size())
if (!m_read_requests.empty())
{
ReadRequest& rr = m_read_requests.front();
// send up to 16 bytes to the wii
+2 -2
View File
@@ -606,9 +606,9 @@ void Update()
void UpdateDevices()
{
// Check if a hardware device must be updated
for (TDeviceMap::const_iterator itr = g_DeviceMap.begin(); itr != g_DeviceMap.end(); ++itr)
for (const auto& entry : g_DeviceMap)
{
if (itr->second->IsOpened() && itr->second->Update())
if (entry.second->IsOpened() && entry.second->Update())
{
break;
}
@@ -59,8 +59,7 @@ bool CWII_IPC_HLE_Device_fs::Close(u32 _CommandAddress, bool _bForce)
static u64 ComputeTotalFileSize(const File::FSTEntry& parentEntry)
{
u64 sizeOfFiles = 0;
const std::vector<File::FSTEntry>& children = parentEntry.children;
for (const auto& entry : children)
for (const File::FSTEntry& entry : parentEntry.children)
{
if (entry.isDirectory)
sizeOfFiles += ComputeTotalFileSize(entry);
@@ -146,10 +145,10 @@ bool CWII_IPC_HLE_Device_fs::IOCtlV(u32 _CommandAddress)
// Decode entities of invalid file system characters so that
// games (such as HP:HBP) will be able to find what they expect.
for (Common::replace_v::const_iterator it = replacements.begin(); it != replacements.end(); ++it)
for (const Common::replace_t& r : replacements)
{
for (size_t j = 0; (j = FileName.find(it->second, j)) != FileName.npos; ++j)
FileName.replace(j, it->second.length(), 1, it->first);
for (size_t j = 0; (j = FileName.find(r.second, j)) != FileName.npos; ++j)
FileName.replace(j, r.second.length(), 1, r.first);
}
strcpy(pFilename, FileName.c_str());
@@ -94,9 +94,9 @@ CWII_IPC_HLE_Device_hid::~CWII_IPC_HLE_Device_hid()
deinit_libusb = true;
}
for ( std::map<u32,libusb_device_handle*>::const_iterator iter = open_devices.begin(); iter != open_devices.end(); ++iter )
for (const auto& device : open_devices)
{
libusb_close(iter->second);
libusb_close(device.second);
}
open_devices.clear();
+2 -2
View File
@@ -582,9 +582,9 @@ void WiiSockMan::Update()
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
FD_ZERO(&except_fds);
for (auto it = WiiSockets.begin(); it != WiiSockets.end(); ++it)
for (auto& entry : WiiSockets)
{
WiiSocket& sock = it->second;
WiiSocket& sock = entry.second;
if (sock.valid())
{
FD_SET(sock.fd, &read_fds);

Some files were not shown because too many files have changed in this diff Show More