From 4094c352036d30e238f2f65895229f749723e471 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 24 Feb 2014 08:58:22 -0500 Subject: [PATCH] Tiny cleanup to WII_IPC_HLE.cpp. - Inlined loop vars in statements where possible. - Eliminate some explicit iterators with foreach loops. - Kill off some newlines that weren't necessary. --- Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp | 81 ++++++++++-------------- 1 file changed, 34 insertions(+), 47 deletions(-) diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp index fadd41422d..0e3b025921 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp @@ -90,7 +90,6 @@ void EnqueReplyCallback(u64 userdata, int) void Init() { - _dbg_assert_msg_(WII_IPC_HLE, g_DeviceMap.empty(), "DeviceMap isn't empty on init"); CWII_IPC_HLE_Device_es::m_ContentFile = ""; u32 i; @@ -107,8 +106,7 @@ void Init() g_DeviceMap[i] = new CWII_IPC_HLE_Device_fs(i, std::string("/dev/fs")); i++; // IOS allows two ES devices at a time< - u32 j; - for (j=0; jIsHardware()) { @@ -148,28 +145,28 @@ void Reset(bool _bHard) g_FdMap[i]->Close(0, true); delete g_FdMap[i]; } + g_FdMap[i] = NULL; } - u32 j; - for (j=0; jsecond) + if (entry.second) { // Force close - itr->second->Close(0, true); + entry.second->Close(0, true); + // Hardware should not be deleted unless it is a hard reset if (_bHard) - delete itr->second; + delete entry.second; } - ++itr; } + if (_bHard) { g_DeviceMap.erase(g_DeviceMap.begin(), g_DeviceMap.end()); @@ -191,14 +188,12 @@ void Shutdown() void SetDefaultContentFile(const std::string& _rFilename) { - TDeviceMap::const_iterator itr = g_DeviceMap.begin(); - while (itr != g_DeviceMap.end()) + for (const auto& entry : g_DeviceMap) { - if (itr->second && itr->second->GetDeviceName().find(std::string("/dev/es")) == 0) + if (entry.second && entry.second->GetDeviceName().find(std::string("/dev/es")) == 0) { - ((CWII_IPC_HLE_Device_es*)itr->second)->LoadWAD(_rFilename); + ((CWII_IPC_HLE_Device_es*)entry.second)->LoadWAD(_rFilename); } - ++itr; } } @@ -214,27 +209,26 @@ void SDIO_EventNotify() if (pDevice) pDevice->EventNotify(); } + int getFreeDeviceId() { - u32 i; - for (i=0; isecond && itr->second->GetDeviceName() == _rDeviceName) - return itr->second; - ++itr; + if (entry.second && entry.second->GetDeviceName() == _rDeviceName) + return entry.second; } return NULL; @@ -269,22 +263,17 @@ void DoState(PointerWrap &p) p.Do(reply_queue); p.Do(last_reply_time); - TDeviceMap::const_iterator itr; - - itr = g_DeviceMap.begin(); - while (itr != g_DeviceMap.end()) + for (const auto& entry : g_DeviceMap) { - if (itr->second->IsHardware()) - { - itr->second->DoState(p); - } - ++itr; + if (entry.second->IsHardware()) + { + entry.second->DoState(p); + } } if (p.GetMode() == PointerWrap::MODE_READ) { - u32 i; - for (i=0; iGetDeviceID(); @@ -320,8 +310,7 @@ void DoState(PointerWrap &p) } else { - u32 i; - for (i=0; iGetDeviceID(); @@ -370,7 +360,6 @@ void ExecuteCommand(u32 _Address) std::string DeviceName; Memory::GetString(DeviceName, Memory::Read_U32(_Address + 0xC)); - WARN_LOG(WII_IPC_HLE, "Trying to open %s as %d", DeviceName.c_str(), DeviceID); if (DeviceID >= 0) { @@ -388,12 +377,12 @@ void ExecuteCommand(u32 _Address) break; } } + if (j == ES_MAX_COUNT) { Memory::Write_U32(FS_EESEXHAUSTED, _Address + 4); CmdSuccess = true; } - } else if (DeviceName.find("/dev/") == 0) { @@ -430,7 +419,6 @@ void ExecuteCommand(u32 _Address) pDevice = NULL; } } - } else { @@ -445,8 +433,7 @@ void ExecuteCommand(u32 _Address) { CmdSuccess = pDevice->Close(_Address); - u32 j; - for (j=0; j