diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index d9fee4ef72..33f041989b 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -161,9 +161,7 @@ bool SupportsVolumeChanges(std::string_view backend) void UpdateSoundStream(Core::System& system) { - SoundStream* sound_stream = system.GetSoundStream(); - - if (sound_stream) + if (SoundStream* sound_stream = system.GetSoundStream()) { int volume = Config::Get(Config::MAIN_AUDIO_MUTED) ? 0 : Config::Get(Config::MAIN_AUDIO_VOLUME); sound_stream->SetVolume(volume); diff --git a/Source/Core/Common/Assembler/GekkoLexer.cpp b/Source/Core/Common/Assembler/GekkoLexer.cpp index f9cd9cd035..5beda6932b 100644 --- a/Source/Core/Common/Assembler/GekkoLexer.cpp +++ b/Source/Core/Common/Assembler/GekkoLexer.cpp @@ -620,9 +620,7 @@ TokenType Lexer::LexStringLit(std::string_view& invalid_reason, Interval& invali const size_t string_start = m_scan_pos.index - 1; TokenType token_type = TokenType::StringLit; - std::optional failure_reason = RunDfa(string_dfa); - - if (failure_reason) + if (std::optional failure_reason = RunDfa(string_dfa)) { token_type = TokenType::Invalid; invalid_reason = *failure_reason; diff --git a/Source/Core/Common/ColorUtil.cpp b/Source/Core/Common/ColorUtil.cpp index 0f1a0dc69c..fdc419d295 100644 --- a/Source/Core/Common/ColorUtil.cpp +++ b/Source/Core/Common/ColorUtil.cpp @@ -18,8 +18,6 @@ static const int s_lut3to8[] = {0x00, 0x24, 0x48, 0x6D, 0x91, 0xB6, 0xDA, 0xFF}; static u32 Decode5A3(u16 val) { - const u32 bg_color = 0x00000000; - int r, g, b, a; if (val & 0x8000) @@ -31,6 +29,7 @@ static u32 Decode5A3(u16 val) } else { + const u32 bg_color = 0x00000000; a = s_lut3to8[(val >> 12) & 0x7]; r = (s_lut4to8[(val >> 8) & 0xf] * a + (bg_color & 0xFF) * (255 - a)) / 255; g = (s_lut4to8[(val >> 4) & 0xf] * a + ((bg_color >> 8) & 0xFF) * (255 - a)) / 255; diff --git a/Source/Core/Common/Crypto/bn.cpp b/Source/Core/Common/Crypto/bn.cpp index 28bd216824..bea0e7d97a 100644 --- a/Source/Core/Common/Crypto/bn.cpp +++ b/Source/Core/Common/Crypto/bn.cpp @@ -71,14 +71,13 @@ void bn_mul(u8* d, const u8* a, const u8* b, const u8* N, const size_t n) void bn_exp(u8* d, const u8* a, const u8* N, const size_t n, const u8* e, const size_t en) { - u8 t[512]; - bn_zero(d, n); d[n - 1] = 1; for (size_t i = 0; i < en; i++) { for (u8 mask = 0x80; mask != 0; mask >>= 1) { + u8 t[512]; bn_mul(t, d, d, N, n); if ((e[i] & mask) != 0) bn_mul(d, t, a, N, n); diff --git a/Source/Core/Common/GL/GLInterface/WGL.cpp b/Source/Core/Common/GL/GLInterface/WGL.cpp index 286859daf6..d3d53f999e 100644 --- a/Source/Core/Common/GL/GLInterface/WGL.cpp +++ b/Source/Core/Common/GL/GLInterface/WGL.cpp @@ -397,8 +397,7 @@ HGLRC GLContextWGL::CreateCoreContext(HDC dc, HGLRC share_context) 0}; // Attempt creating this context. - HGLRC core_context = wglCreateContextAttribsARB(dc, share_context, attribs.data()); - if (core_context) + if (HGLRC core_context = wglCreateContextAttribsARB(dc, share_context, attribs.data())) { INFO_LOG_FMT(VIDEO, "WGL: Created a GL {}.{} core context", version.first, version.second); return core_context; diff --git a/Source/Core/Common/GL/GLUtil.cpp b/Source/Core/Common/GL/GLUtil.cpp index 9f65e7158b..e4700abb8a 100644 --- a/Source/Core/Common/GL/GLUtil.cpp +++ b/Source/Core/Common/GL/GLUtil.cpp @@ -97,14 +97,13 @@ GLuint CompileProgram(const std::string& vertexShader, const std::string& fragme void EnablePrimitiveRestart(const GLContext* context) { - constexpr GLuint PRIMITIVE_RESTART_INDEX = 65535; - if (context->IsGLES()) { glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); } else { + constexpr GLuint PRIMITIVE_RESTART_INDEX = 65535; if (GLExtensions::Version() >= 310) { glEnable(GL_PRIMITIVE_RESTART); diff --git a/Source/Core/Common/GekkoDisassembler.cpp b/Source/Core/Common/GekkoDisassembler.cpp index 46905c8773..ad2daffec8 100644 --- a/Source/Core/Common/GekkoDisassembler.cpp +++ b/Source/Core/Common/GekkoDisassembler.cpp @@ -796,7 +796,6 @@ void GekkoDisassembler::mspr(u32 in, int smode) { int d = (int)PPCGETD(in); int spr = (int)((PPCGETB(in) << 5) + PPCGETA(in)); - int fmt = 0; if (in & 1) { @@ -804,6 +803,7 @@ void GekkoDisassembler::mspr(u32 in, int smode) } else { + int fmt = 0; const char* x; switch (spr) { diff --git a/Source/Core/Common/MinizipUtil.h b/Source/Core/Common/MinizipUtil.h index 29b365c028..927793a328 100644 --- a/Source/Core/Common/MinizipUtil.h +++ b/Source/Core/Common/MinizipUtil.h @@ -15,8 +15,6 @@ namespace Common // Reads all of the current file. destination must be big enough to fit the whole file. inline bool ReadFileFromZip(unzFile file, u8* destination, u64 len) { - const u64 MAX_BUFFER_SIZE = 65535; - if (unzOpenCurrentFile(file) != UNZ_OK) return false; @@ -25,6 +23,7 @@ inline bool ReadFileFromZip(unzFile file, u8* destination, u64 len) u64 bytes_to_go = len; while (bytes_to_go > 0) { + const u64 MAX_BUFFER_SIZE = 65535; // NOTE: multiples of 4G can't cause read_len == 0 && bytes_to_go > 0, as MAX_BUFFER_SIZE is // small. const u32 read_len = static_cast(std::min(bytes_to_go, MAX_BUFFER_SIZE)); diff --git a/Source/Core/Common/SPSCQueue.h b/Source/Core/Common/SPSCQueue.h index 27a0a8f282..788cac2232 100644 --- a/Source/Core/Common/SPSCQueue.h +++ b/Source/Core/Common/SPSCQueue.h @@ -92,9 +92,7 @@ private: ElementPtr() : next(nullptr) {} ~ElementPtr() { - ElementPtr* next_ptr = next.load(); - - if (next_ptr) + if (ElementPtr* next_ptr = next.load()) delete next_ptr; } diff --git a/Source/Core/Common/x64Emitter.cpp b/Source/Core/Common/x64Emitter.cpp index 14458ae7d4..0a43c26d58 100644 --- a/Source/Core/Common/x64Emitter.cpp +++ b/Source/Core/Common/x64Emitter.cpp @@ -175,8 +175,7 @@ u8* XEmitter::AlignCodeTo(size_t alignment) { ASSERT_MSG(DYNA_REC, alignment != 0 && (alignment & (alignment - 1)) == 0, "Alignment must be power of two"); - u64 c = reinterpret_cast(code) & (alignment - 1); - if (c) + if (u64 c = reinterpret_cast(code) & (alignment - 1)) ReserveCodeSpace(static_cast(alignment - c)); return code; } diff --git a/Source/Core/Common/x64FPURoundMode.cpp b/Source/Core/Common/x64FPURoundMode.cpp index 06b66ec527..6c09399586 100644 --- a/Source/Core/Common/x64FPURoundMode.cpp +++ b/Source/Core/Common/x64FPURoundMode.cpp @@ -20,7 +20,6 @@ void SetSIMDMode(RoundMode rounding_mode, bool non_ieee_mode) // OR-mask for disabling FPU exceptions (bits 7-12 in the MXCSR register) const u32 EXCEPTION_MASK = 0x1F80; // Flush-To-Zero (non-IEEE mode: denormal outputs are set to +/- 0) - const u32 FTZ = 0x8000; // lookup table for FPSCR.RN-to-MXCSR.RC translation static const u32 simd_rounding_table[] = { (0 << 13) | EXCEPTION_MASK, // nearest @@ -32,6 +31,7 @@ void SetSIMDMode(RoundMode rounding_mode, bool non_ieee_mode) if (non_ieee_mode) { + const u32 FTZ = 0x8000; csr |= FTZ; } _mm_setcsr(csr); diff --git a/Source/Core/Core/ARDecrypt.cpp b/Source/Core/Core/ARDecrypt.cpp index 46ca74d159..a2d5f914db 100644 --- a/Source/Core/Core/ARDecrypt.cpp +++ b/Source/Core/Core/ARDecrypt.cpp @@ -466,8 +466,7 @@ void DecryptARCode(std::vector vCodes, std::vector* ops) Common::ToUpper(&s); } - const u32 ret = alphatobin(uCodes.data(), vCodes, (int)vCodes.size()); - if (ret) + if (const u32 ret = alphatobin(uCodes.data(), vCodes, (int)vCodes.size())) { // Return value is index + 1, 0 being the success flag value. PanicAlertFmtT( diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 1fd77d2c30..b879636ee9 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -237,8 +237,7 @@ std::unique_ptr BootParameters::GenerateFromFile(std::vector disc = DiscIO::CreateDisc(path); - if (disc) + if (std::unique_ptr disc = DiscIO::CreateDisc(path)) { return std::make_unique(Disc{std::move(path), std::move(disc), paths}, std::move(boot_session_data_)); @@ -267,15 +266,13 @@ std::unique_ptr BootParameters::GenerateFromFile(std::vector wad = DiscIO::CreateWAD(std::move(path)); - if (wad) + if (std::unique_ptr wad = DiscIO::CreateWAD(std::move(path))) return std::make_unique(std::move(*wad), std::move(boot_session_data_)); } if (extension == ".json") { - auto descriptor = DiscIO::ParseGameModDescriptorFile(path); - if (descriptor) + if (auto descriptor = DiscIO::ParseGameModDescriptorFile(path)) { auto boot_params = GenerateFromFile(descriptor->base_file, std::move(boot_session_data_)); if (!boot_params) diff --git a/Source/Core/Core/Boot/ElfReader.cpp b/Source/Core/Core/Boot/ElfReader.cpp index 2fc428399a..bf2d56ecbc 100644 --- a/Source/Core/Core/Boot/ElfReader.cpp +++ b/Source/Core/Core/Boot/ElfReader.cpp @@ -115,9 +115,8 @@ const char* ElfReader::GetSectionName(int section) const return nullptr; int nameOffset = sections[section].sh_name; - char* ptr = (char*)GetSectionDataPtr(header->e_shstrndx); - if (ptr) + if (char* ptr = (char*)GetSectionDataPtr(header->e_shstrndx)) return ptr + nameOffset; else return nullptr; diff --git a/Source/Core/Core/CheatSearch.cpp b/Source/Core/Core/CheatSearch.cpp index a3bd123e0c..6dbdcb2411 100644 --- a/Source/Core/Core/CheatSearch.cpp +++ b/Source/Core/Core/CheatSearch.cpp @@ -71,8 +71,7 @@ static std::vector ToByteVector(const T& val) std::vector Cheats::GetValueAsByteVector(const Cheats::SearchValue& value) { - DataType type = GetDataType(value); - switch (type) + switch (DataType type = GetDataType(value)) { case Cheats::DataType::U8: return {std::get(value.m_value)}; diff --git a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp index 88fa7c0696..e0f30bca56 100644 --- a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp +++ b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp @@ -207,8 +207,7 @@ private: // Somewhat hacky support for IPL.SADR. The setting only stores the // first 4 bytes even thought the SYSCONF entry is much bigger. u32 value = info->GetDefaultValue(); - SysConf::Entry* entry = sysconf.GetEntry(key); - if (entry) + if (SysConf::Entry* entry = sysconf.GetEntry(key)) { std::memcpy(&value, entry->bytes.data(), std::min(entry->bytes.size(), sizeof(u32))); diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index a284cbe266..fb9edaeebd 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -465,8 +465,7 @@ std::string SConfig::GetGameTDBImageRegionCode(bool wii, DiscIO::Region region) return "KO"; case DiscIO::Region::PAL: { - const auto user_lang = GetCurrentLanguage(wii); - switch (user_lang) + switch (const auto user_lang = GetCurrentLanguage(wii)) { case DiscIO::Language::German: return "DE"; diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index bf850a253d..020fb12233 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -981,8 +981,7 @@ void UpdateWantDeterminism(Core::System& system, bool initial) const Core::CPUThreadGuard guard(system); s_wants_determinism = new_want_determinism; - const auto ios = system.GetIOS(); - if (ios) + if (const auto ios = system.GetIOS()) ios->UpdateWantDeterminism(new_want_determinism); system.GetFifo().UpdateWantDeterminism(new_want_determinism); diff --git a/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp b/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp index 6d8527f657..36bdf9bbfa 100644 --- a/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp +++ b/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp @@ -176,9 +176,7 @@ void DSPEmitter::EmitInstruction(UDSPInstruction inst) // Call extended if (op_template->extended) { - const auto jit_function = GetExtOp(inst); - - if (jit_function) + if (const auto jit_function = GetExtOp(inst)) { (this->*jit_function)(inst); ext_is_jit = true; @@ -195,8 +193,7 @@ void DSPEmitter::EmitInstruction(UDSPInstruction inst) } // Main instruction - const auto jit_function = GetOp(inst); - if (jit_function) + if (const auto jit_function = GetOp(inst)) { (this->*jit_function)(inst); } diff --git a/Source/Core/Core/DSP/LabelMap.cpp b/Source/Core/Core/DSP/LabelMap.cpp index 19a7a0ae77..d969960a70 100644 --- a/Source/Core/Core/DSP/LabelMap.cpp +++ b/Source/Core/Core/DSP/LabelMap.cpp @@ -44,8 +44,7 @@ void LabelMap::RegisterDefaults() bool LabelMap::RegisterLabel(std::string label, u16 lval, LabelType type) { - const std::optional old_value = GetLabelValue(label); - if (old_value) + if (const std::optional old_value = GetLabelValue(label)) { if (old_value != lval) { diff --git a/Source/Core/Core/HLE/HLE_OS.cpp b/Source/Core/Core/HLE/HLE_OS.cpp index a81f294107..0966cadea8 100644 --- a/Source/Core/Core/HLE/HLE_OS.cpp +++ b/Source/Core/Core/HLE/HLE_OS.cpp @@ -389,8 +389,7 @@ std::string GetStringVA(HLEPrintArgs* args, std::string_view string) break; } - const char format_specifier = string[i]; - switch (format_specifier) + switch (const char format_specifier = string[i]) { case 's': { diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/AX.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/AX.cpp index 2dc000dbfe..8760305cd8 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/AX.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/AX.cpp @@ -130,9 +130,7 @@ void AXUCode::HandleCommandList() bool end = false; while (!end) { - u16 cmd = m_cmdlist[curr_idx++]; - - switch (cmd) + switch (u16 cmd = m_cmdlist[curr_idx++]) { // Some of these commands are unknown, or unused in this AX HLE. // We still need to skip their arguments using "curr_idx += N". @@ -416,7 +414,6 @@ void AXUCode::ProcessPBList(u32 pb_addr) { // Samples per millisecond. In theory DSP sampling rate can be changed from // 32KHz to 48KHz, but AX always process at 32KHz. - constexpr u32 spms = 32; AXPB pb; @@ -434,6 +431,7 @@ void AXUCode::ProcessPBList(u32 pb_addr) for (int curr_ms = 0; curr_ms < 5; ++curr_ms) { + constexpr u32 spms = 32; ApplyUpdatesForMs(curr_ms, pb, pb.updates.num_updates, updates); ProcessVoice(static_cast(m_accelerator.get()), pb, buffers, spms, diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/AXWii.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/AXWii.cpp index 53be74371d..9a9cd645d7 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/AXWii.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/AXWii.cpp @@ -423,7 +423,6 @@ void AXWiiUCode::ProcessPBList(u32 pb_addr) { // Samples per millisecond. In theory DSP sampling rate can be changed from // 32KHz to 48KHz, but AX always process at 32KHz. - constexpr u32 spms = 32; AXPBWii pb; @@ -447,6 +446,7 @@ void AXWiiUCode::ProcessPBList(u32 pb_addr) { for (int curr_ms = 0; curr_ms < 3; ++curr_ms) { + constexpr u32 spms = 32; ApplyUpdatesForMs(curr_ms, pb, num_updates, updates); ProcessVoice(static_cast(m_accelerator.get()), pb, buffers, spms, ConvertMixerControl(HILO_TO_32(pb.mixer_control)), diff --git a/Source/Core/Core/HW/DVD/DVDInterface.cpp b/Source/Core/Core/HW/DVD/DVDInterface.cpp index babb500902..2bc332bc7f 100644 --- a/Source/Core/Core/HW/DVD/DVDInterface.cpp +++ b/Source/Core/Core/HW/DVD/DVDInterface.cpp @@ -428,9 +428,8 @@ void DVDInterface::EjectDiscCallback(Core::System& system, u64 userdata, s64 cyc void DVDInterface::InsertDiscCallback(Core::System& system, u64 userdata, s64 cyclesLate) { auto& di = system.GetDVDInterface(); - std::unique_ptr new_disc = DiscIO::CreateDisc(di.m_disc_path_to_insert); - if (new_disc) + if (std::unique_ptr new_disc = DiscIO::CreateDisc(di.m_disc_path_to_insert)) di.SetDisc(std::move(new_disc), {}); else PanicAlertFmtT("The disc that was about to be inserted couldn't be found."); diff --git a/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp b/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp index 86d3f89420..afa5f23914 100644 --- a/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp +++ b/Source/Core/Core/HW/EXI/BBA/BuiltIn.cpp @@ -249,12 +249,12 @@ std::optional> CEXIETHERNET::BuiltInBBAInterface::TryGetDataFromSocket(StackRef* ref) { std::size_t datasize = 0; // Set by socket.receive using a non-const reference - unsigned short remote_port; switch (ref->type) { case IPPROTO_UDP: { + unsigned short remote_port; std::array buffer; ref->udp_socket.receive(buffer.data(), MAX_UDP_LENGTH, datasize, ref->target, remote_port); if (datasize > 0) @@ -341,7 +341,6 @@ CEXIETHERNET::BuiltInBBAInterface::TryGetDataFromSocket(StackRef* ref) void CEXIETHERNET::BuiltInBBAInterface::HandleTCPFrame(const Common::TCPPacket& packet) { const auto& [hwdata, ip_header, tcp_header, ip_options, tcp_options, data] = packet; - sf::IpAddress target; StackRef* ref = m_network_ref.GetTCPSlot(tcp_header.source_port, tcp_header.destination_port, std::bit_cast(ip_header.destination_addr)); const u16 flags = ntohs(tcp_header.properties) & 0xfff; @@ -369,6 +368,7 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleTCPFrame(const Common::TCPPacket& } else if (flags & TCP_FLAG_SIN) { + sf::IpAddress target; // new connection if (ref != nullptr) return; diff --git a/Source/Core/Core/HW/EXI/BBA/TAP_Win32.cpp b/Source/Core/Core/HW/EXI/BBA/TAP_Win32.cpp index bbfdfa19de..206d924d73 100644 --- a/Source/Core/Core/HW/EXI/BBA/TAP_Win32.cpp +++ b/Source/Core/Core/HW/EXI/BBA/TAP_Win32.cpp @@ -30,9 +30,7 @@ bool IsTAPDevice(const TCHAR* guid) TCHAR unit_string[256]; HKEY unit_key; TCHAR component_id_string[] = _T("ComponentId"); - TCHAR component_id[256]; TCHAR net_cfg_instance_id_string[] = _T("NetCfgInstanceId"); - TCHAR net_cfg_instance_id[256]; DWORD data_type; len = _countof(enum_name); @@ -54,21 +52,21 @@ bool IsTAPDevice(const TCHAR* guid) } else { + TCHAR component_id[256]; len = sizeof(component_id); status = RegQueryValueEx(unit_key, component_id_string, nullptr, &data_type, (LPBYTE)component_id, &len); if (!(status != ERROR_SUCCESS || data_type != REG_SZ)) { + TCHAR net_cfg_instance_id[256]; len = sizeof(net_cfg_instance_id); status = RegQueryValueEx(unit_key, net_cfg_instance_id_string, nullptr, &data_type, (LPBYTE)net_cfg_instance_id, &len); if (status == ERROR_SUCCESS && data_type == REG_SZ) { - TCHAR* const component_id_sub = _tcsstr(component_id, TAP_COMPONENT_ID); - - if (component_id_sub) + if (TCHAR* const component_id_sub = _tcsstr(component_id, TAP_COMPONENT_ID)) { if (!_tcscmp(component_id_sub, TAP_COMPONENT_ID) && !_tcscmp(net_cfg_instance_id, guid)) { @@ -112,7 +110,6 @@ bool GetGUIDs(std::vector>& guids) TCHAR enum_name[256]; TCHAR connection_string[256]; HKEY connection_key; - TCHAR name_data[256]; DWORD name_type; const TCHAR name_string[] = _T("Name"); @@ -130,6 +127,7 @@ bool GetGUIDs(std::vector>& guids) if (status == ERROR_SUCCESS) { + TCHAR name_data[256]; len = sizeof(name_data); status = RegQueryValueEx(connection_key, name_string, nullptr, &name_type, (LPBYTE)name_data, &len); diff --git a/Source/Core/Core/HW/ProcessorInterface.cpp b/Source/Core/Core/HW/ProcessorInterface.cpp index fc26896a54..3e84e4de8a 100644 --- a/Source/Core/Core/HW/ProcessorInterface.cpp +++ b/Source/Core/Core/HW/ProcessorInterface.cpp @@ -236,8 +236,7 @@ void ProcessorInterfaceManager::IOSNotifyResetButtonCallback(Core::System& syste if (!ios) return; - auto stm = ios->GetDeviceByName("/dev/stm/eventhook"); - if (stm) + if (auto stm = ios->GetDeviceByName("/dev/stm/eventhook")) std::static_pointer_cast(stm)->ResetButton(); } @@ -248,8 +247,7 @@ void ProcessorInterfaceManager::IOSNotifyPowerButtonCallback(Core::System& syste if (!ios) return; - auto stm = ios->GetDeviceByName("/dev/stm/eventhook"); - if (stm) + if (auto stm = ios->GetDeviceByName("/dev/stm/eventhook")) std::static_pointer_cast(stm)->PowerButton(); } diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp index f8150a6339..60049e20b7 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp @@ -49,10 +49,9 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length) return -1; // Read the command - const auto command = static_cast(buffer[0]); // Handle it - switch (command) + switch (const auto command = static_cast(buffer[0])) { case EBufferCommands::CMD_STATUS: case EBufferCommands::CMD_RESET: diff --git a/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp b/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp index 6c1e34b9bb..c9684fa5d5 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceKeyboard.cpp @@ -27,10 +27,9 @@ int CSIDevice_Keyboard::RunBuffer(u8* buffer, int request_length) ISIDevice::RunBuffer(buffer, request_length); // Read the command - const auto command = static_cast(buffer[0]); // Handle it - switch (command) + switch (const auto command = static_cast(buffer[0])) { case EBufferCommands::CMD_STATUS: case EBufferCommands::CMD_RESET: diff --git a/Source/Core/Core/HW/WiimoteEmu/I2CBus.cpp b/Source/Core/Core/HW/WiimoteEmu/I2CBus.cpp index 1c231f7944..b8612bdf3d 100644 --- a/Source/Core/Core/HW/WiimoteEmu/I2CBus.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/I2CBus.cpp @@ -26,10 +26,8 @@ int I2CBus::BusRead(u8 slave_addr, u8 addr, int count, u8* data_out) { for (auto& slave : m_slaves) { - auto const bytes_read = slave->BusRead(slave_addr, addr, count, data_out); - // A slave responded, we are done. - if (bytes_read) + if (auto const bytes_read = slave->BusRead(slave_addr, addr, count, data_out)) return bytes_read; } @@ -40,10 +38,8 @@ int I2CBus::BusWrite(u8 slave_addr, u8 addr, int count, const u8* data_in) { for (auto& slave : m_slaves) { - auto const bytes_written = slave->BusWrite(slave_addr, addr, count, data_in); - // A slave responded, we are done. - if (bytes_written) + if (auto const bytes_written = slave->BusWrite(slave_addr, addr, count, data_in)) return bytes_written; } diff --git a/Source/Core/Core/HW/WiimoteReal/IOWin.cpp b/Source/Core/Core/HW/WiimoteReal/IOWin.cpp index f931bb10a3..e7414d9790 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOWin.cpp +++ b/Source/Core/Core/HW/WiimoteReal/IOWin.cpp @@ -267,14 +267,13 @@ int IOWritePerWriteFile(HANDLE& dev_handle, OVERLAPPED& hid_overlap_write, LPCVOID write_buffer = buf + 1; DWORD bytes_to_write = (DWORD)(len - 1); - u8 resized_buffer[MAX_PAYLOAD]; - // Resize the buffer, if the underlying HID Class driver needs the buffer to be the size of // HidCaps.OuputReportSize // In case of Wiimote HidCaps.OuputReportSize is 22 Byte. // This is currently needed by the Toshiba Bluetooth Stack. if ((write_method == WWM_WRITE_FILE_LARGEST_REPORT_SIZE) && (MAX_PAYLOAD > len)) { + u8 resized_buffer[MAX_PAYLOAD]; std::copy(buf, buf + len, resized_buffer); std::fill(resized_buffer + len, resized_buffer + MAX_PAYLOAD, 0); write_buffer = resized_buffer + 1; @@ -286,9 +285,7 @@ int IOWritePerWriteFile(HANDLE& dev_handle, OVERLAPPED& hid_overlap_write, WriteFile(dev_handle, write_buffer, bytes_to_write, &bytes_written, &hid_overlap_write); if (!result) { - const DWORD error = GetLastError(); - - switch (error) + switch (const DWORD error = GetLastError()) { case ERROR_INVALID_USER_BUFFER: INFO_LOG_FMT(WIIMOTE, "IOWrite[WWM_WRITE_FILE]: Falling back to SetOutputReport"); @@ -466,12 +463,12 @@ bool IsWiimote(const std::basic_string& device_path, WinWriteMethod& meth Common::ScopeGuard handle_guard{[&dev_handle] { CloseHandle(dev_handle); }}; - u8 buf[MAX_PAYLOAD]; u8 const req_status_report[] = {WR_SET_REPORT | BT_OUTPUT, u8(OutputReportID::RequestStatus), 0}; int invalid_report_count = 0; int rc = WriteToHandle(dev_handle, method, req_status_report, sizeof(req_status_report)); while (rc > 0) { + u8 buf[MAX_PAYLOAD]; rc = ReadFromHandle(dev_handle, buf); if (rc <= 0) break; @@ -712,9 +709,7 @@ size_t GetReportSize(u8 rid) { using namespace WiimoteCommon; - const auto report_id = static_cast(rid); - - switch (report_id) + switch (const auto report_id = static_cast(rid)) { case InputReportID::Status: return sizeof(InputReportStatus); diff --git a/Source/Core/Core/IOS/Crypto/AesDevice.cpp b/Source/Core/Core/IOS/Crypto/AesDevice.cpp index caf7879825..36fbe5cc3d 100644 --- a/Source/Core/Core/IOS/Crypto/AesDevice.cpp +++ b/Source/Core/Core/IOS/Crypto/AesDevice.cpp @@ -35,9 +35,8 @@ std::optional AesDevice::IOCtlV(const IOCtlVRequest& request) auto& system = GetSystem(); auto& memory = system.GetMemory(); HLE::ReturnCode return_code = IPC_EINVAL; - AesIoctlv command = static_cast(request.request); - switch (command) + switch (AesIoctlv command = static_cast(request.request)) { case AesIoctlv::Copy: { diff --git a/Source/Core/Core/IOS/Crypto/Sha.cpp b/Source/Core/Core/IOS/Crypto/Sha.cpp index de4415e140..e27e697f2e 100644 --- a/Source/Core/Core/IOS/Crypto/Sha.cpp +++ b/Source/Core/Core/IOS/Crypto/Sha.cpp @@ -82,9 +82,8 @@ HLE::ReturnCode ShaDevice::ProcessShaCommand(ShaIoctlv command, const IOCtlVRequ std::optional ShaDevice::IOCtlV(const IOCtlVRequest& request) { HLE::ReturnCode return_code = IPC_EINVAL; - ShaIoctlv command = static_cast(request.request); - switch (command) + switch (ShaIoctlv command = static_cast(request.request)) { case ShaIoctlv::InitState: case ShaIoctlv::ContributeState: diff --git a/Source/Core/Core/IOS/DI/DI.cpp b/Source/Core/Core/IOS/DI/DI.cpp index 0f1413229f..70ff864582 100644 --- a/Source/Core/Core/IOS/DI/DI.cpp +++ b/Source/Core/Core/IOS/DI/DI.cpp @@ -108,8 +108,7 @@ void DIDevice::ProcessQueuedIOCtl() auto& system = GetSystem(); IOCtlRequest request{system, m_executing_command->m_request_address}; - auto finished = StartIOCtl(request); - if (finished) + if (auto finished = StartIOCtl(request)) { system.GetCoreTiming().ScheduleEvent(IPC_OVERHEAD_TICKS, s_finish_executing_di_command, static_cast(finished.value())); @@ -628,8 +627,7 @@ void DIDevice::InterruptFromDVDInterface(DVD::DIInterruptType interrupt_type) break; } - auto di = GetDevice(); - if (di) + if (auto di = GetDevice()) { di->FinishDICommand(result); } @@ -644,8 +642,7 @@ void DIDevice::FinishDICommandCallback(Core::System& system, u64 userdata, s64 t { const DIResult result = static_cast(userdata); - auto di = GetDevice(); - if (di) + if (auto di = GetDevice()) di->FinishDICommand(result); else PanicAlertFmt("IOS::HLE::DIDevice: Received interrupt from DI when device wasn't registered!"); diff --git a/Source/Core/Core/IOS/Device.cpp b/Source/Core/Core/IOS/Device.cpp index 3fdbcaed62..f8a8bb6f30 100644 --- a/Source/Core/Core/IOS/Device.cpp +++ b/Source/Core/Core/IOS/Device.cpp @@ -28,8 +28,7 @@ OpenRequest::OpenRequest(Core::System& system, const u32 address_) : Request(sys auto& memory = system.GetMemory(); path = memory.GetString(memory.Read_U32(address + 0xc)); flags = static_cast(memory.Read_U32(address + 0x10)); - const EmulationKernel* ios = system.GetIOS(); - if (ios) + if (const EmulationKernel* ios = system.GetIOS()) { uid = ios->GetUidForPPC(); gid = ios->GetGidForPPC(); diff --git a/Source/Core/Core/IOS/ES/Formats.cpp b/Source/Core/Core/IOS/ES/Formats.cpp index 2826f7aed5..ee7e03c348 100644 --- a/Source/Core/Core/IOS/ES/Formats.cpp +++ b/Source/Core/Core/IOS/ES/Formats.cpp @@ -686,8 +686,7 @@ u32 UIDSys::GetNextUID() const u32 UIDSys::GetOrInsertUIDForTitle(const u64 title_id) { - const u32 current_uid = GetUIDFromTitle(title_id); - if (current_uid) + if (const u32 current_uid = GetUIDFromTitle(title_id)) { INFO_LOG_FMT(IOS_ES, "Title {:016x} already exists in uid.sys", title_id); return current_uid; diff --git a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp index da5fa6d983..af27461ceb 100644 --- a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp +++ b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp @@ -397,8 +397,6 @@ void HostFileSystem::DoState(PointerWrap& p) movie.IsMovieActive() && Core::WiiRootIsTemporary(); p.Do(original_save_state_made_during_movie_recording); - u32 temp_val = 0; - if (!p.IsReadMode()) { DoStateWriteOrMeasure(p, "/tmp"); @@ -415,6 +413,7 @@ void HostFileSystem::DoState(PointerWrap& p) } else // case where we're in read mode. { + u32 temp_val = 0; DoStateRead(p, "/tmp"); if (!movie.IsMovieActive() || !original_save_state_made_during_movie_recording || !Core::WiiRootIsTemporary() || diff --git a/Source/Core/Core/IOS/IOS.cpp b/Source/Core/Core/IOS/IOS.cpp index 8eab961228..e2bb6415be 100644 --- a/Source/Core/Core/IOS/IOS.cpp +++ b/Source/Core/Core/IOS/IOS.cpp @@ -236,7 +236,6 @@ void RAMOverrideForIOSMemoryValues(Memory::MemoryManager& memory, MemorySetupTyp const u32 mem1_physical_size = memory.GetRamSizeReal(); const u32 mem1_simulated_size = memory.GetRamSizeReal(); const u32 mem1_end = Memory::MEM1_BASE_ADDR + mem1_simulated_size; - const u32 mem1_arena_begin = 0; const u32 mem1_arena_end = mem1_end; const u32 mem2_physical_size = memory.GetExRamSizeReal(); const u32 mem2_simulated_size = memory.GetExRamSizeReal(); @@ -250,6 +249,7 @@ void RAMOverrideForIOSMemoryValues(Memory::MemoryManager& memory, MemorySetupTyp if (setup_type == MemorySetupType::Full) { + const u32 mem1_arena_begin = 0; // Overwriting these after the game's apploader sets them would be bad memory.Write_U32(mem1_physical_size, ADDR_MEM1_SIZE); memory.Write_U32(mem1_simulated_size, ADDR_MEM1_SIM_SIZE); @@ -957,8 +957,7 @@ void Init(Core::System& system) s_event_enqueue = core_timing.RegisterEvent("IPCEvent", [](Core::System& system_, u64 userdata, s64) { - auto* ios = system_.GetIOS(); - if (ios) + if (auto* ios = system_.GetIOS()) ios->HandleIPCEvent(userdata); }); diff --git a/Source/Core/Core/IOS/Network/IP/Top.cpp b/Source/Core/Core/IOS/Network/IP/Top.cpp index 2c078779b9..394af8fd5a 100644 --- a/Source/Core/Core/IOS/Network/IP/Top.cpp +++ b/Source/Core/Core/IOS/Network/IP/Top.cpp @@ -69,8 +69,8 @@ NetIPTopDevice::NetIPTopDevice(EmulationKernel& ios, const std::string& device_n : EmulationDevice(ios, device_name) { m_work_queue.Reset("Network Worker", [this](AsyncTask task) { - const IPCReply reply = task.handler(); { + const IPCReply reply = task.handler(); std::lock_guard lg(m_async_reply_lock); m_async_replies.emplace(AsyncReply{task.request, reply.return_value}); } @@ -1087,9 +1087,9 @@ IPCReply NetIPTopDevice::HandleGetAddressInfoRequest(const IOCtlVRequest& reques u32 sockoffset = addr + 0x460; if (ret == 0) { - constexpr size_t WII_ADDR_INFO_SIZE = 0x20; for (addrinfo* result_iter = result; result_iter != nullptr; result_iter = result_iter->ai_next) { + constexpr size_t WII_ADDR_INFO_SIZE = 0x20; memory.Write_U32(result_iter->ai_flags, addr); memory.Write_U32(result_iter->ai_family, addr + 0x04); memory.Write_U32(result_iter->ai_socktype, addr + 0x08); diff --git a/Source/Core/Core/IOS/Network/KD/NWC24Config.cpp b/Source/Core/Core/IOS/Network/KD/NWC24Config.cpp index b191642543..733775896f 100644 --- a/Source/Core/Core/IOS/Network/KD/NWC24Config.cpp +++ b/Source/Core/Core/IOS/Network/KD/NWC24Config.cpp @@ -28,8 +28,7 @@ void NWC24Config::ReadConfig() { if (file->Read(&m_data, 1)) { - const s32 config_error = CheckNwc24Config(); - if (config_error) + if (const s32 config_error = CheckNwc24Config()) ERROR_LOG_FMT(IOS_WC24, "There is an error in the config for for WC24: {}", config_error); return; diff --git a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp index 14553199d6..2bb141dbe8 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp +++ b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp @@ -162,8 +162,8 @@ NetKDRequestDevice::NetKDRequestDevice(EmulationKernel& ios, const std::string& m_scheduler_buffer[1] = Common::swap32(-1); m_work_queue.Reset("WiiConnect24 Worker", [this](AsyncTask task) { - const IPCReply reply = task.handler(); { + const IPCReply reply = task.handler(); std::lock_guard lg(m_async_reply_lock); m_async_replies.emplace(AsyncReply{task.request, reply.return_value}); } @@ -178,8 +178,7 @@ NetKDRequestDevice::NetKDRequestDevice(EmulationKernel& ios, const std::string& NetKDRequestDevice::~NetKDRequestDevice() { - auto socket_manager = GetEmulationKernel().GetSocketManager(); - if (socket_manager) + if (auto socket_manager = GetEmulationKernel().GetSocketManager()) socket_manager->Clean(); { diff --git a/Source/Core/Core/IOS/Network/SSL.cpp b/Source/Core/Core/IOS/Network/SSL.cpp index 36caab6305..9ff5efaece 100644 --- a/Source/Core/Core/IOS/Network/SSL.cpp +++ b/Source/Core/Core/IOS/Network/SSL.cpp @@ -243,8 +243,7 @@ std::optional NetSSLDevice::IOCtlV(const IOCtlVRequest& request) int verifyOption = memory.Read_U32(BufferOut); std::string hostname = memory.GetString(BufferOut2, BufferOutSize2); - int freeSSL = GetSSLFreeID(); - if (freeSSL) + if (int freeSSL = GetSSLFreeID()) { int sslID = freeSSL - 1; WII_SSL* ssl = &_SSL[sslID]; diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp index 8e1b8b64b3..17fae3e74b 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp @@ -1235,8 +1235,7 @@ void BluetoothEmuDevice::CommandDisconnect(u32 input_address) SendEventCommandStatus(HCI_CMD_DISCONNECT); SendEventDisconnect(disconnect.con_handle, disconnect.reason); - WiimoteDevice* wiimote = AccessWiimote(disconnect.con_handle); - if (wiimote) + if (WiimoteDevice* wiimote = AccessWiimote(disconnect.con_handle)) wiimote->EventDisconnect(disconnect.reason); } diff --git a/Source/Core/Core/IOS/USB/Emulated/Infinity.cpp b/Source/Core/Core/IOS/USB/Emulated/Infinity.cpp index 34a2f40698..97879e3a42 100644 --- a/Source/Core/Core/IOS/USB/Emulated/Infinity.cpp +++ b/Source/Core/Core/IOS/USB/Emulated/Infinity.cpp @@ -681,16 +681,16 @@ bool InfinityBase::CreateFigure(const std::string& file_path, u32 figure_num) // Create a 320 byte file with standard NFC read/write permissions std::array file_data{}; - u32 first_block = 0x17878E; - u32 other_blocks = 0x778788; for (s8 i = 2; i >= 0; i--) { + u32 first_block = 0x17878E; file_data[0x38 - i] = u8((first_block >> i * 8) & 0xFF); } for (u32 index = 1; index < 0x05; index++) { for (s8 i = 2; i >= 0; i--) { + u32 other_blocks = 0x778788; file_data[((index * 0x40) + 0x38) - i] = u8((other_blocks >> i * 8) & 0xFF); } } diff --git a/Source/Core/Core/IOS/USB/Emulated/Skylanders/SkylanderCrypto.cpp b/Source/Core/Core/IOS/USB/Emulated/Skylanders/SkylanderCrypto.cpp index 3361498b80..62292cf0d5 100644 --- a/Source/Core/Core/IOS/USB/Emulated/Skylanders/SkylanderCrypto.cpp +++ b/Source/Core/Core/IOS/USB/Emulated/Skylanders/SkylanderCrypto.cpp @@ -15,8 +15,6 @@ namespace IOS::HLE::USB::SkylanderCrypto { u16 ComputeCRC16(std::span data) { - const u16 polynomial = 0x1021; - u16 crc = 0xFFFF; for (size_t i = 0; i < data.size(); ++i) @@ -27,6 +25,7 @@ u16 ComputeCRC16(std::span data) { if (Common::ExtractBit(crc, 15)) { + const u16 polynomial = 0x1021; crc = (crc << 1) ^ polynomial; } else @@ -41,7 +40,6 @@ u16 ComputeCRC16(std::span data) // CRC-64 algorithm that is limited to 48 bits every iteration u64 ComputeCRC48(std::span data) { - const u64 polynomial = 0x42f0e1eba9ea3693; const u64 initial_register_value = 2ULL * 2ULL * 3ULL * 1103ULL * 12868356821ULL; u64 crc = initial_register_value; @@ -52,6 +50,7 @@ u64 ComputeCRC48(std::span data) { if (Common::ExtractBit(crc, 47)) { + const u64 polynomial = 0x42f0e1eba9ea3693; crc = (crc << 1) ^ polynomial; } else diff --git a/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp b/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp index b60339a8f1..71f011b335 100644 --- a/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp +++ b/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp @@ -204,10 +204,9 @@ void USB_HIDv4::TriggerDeviceChangeReply() return; } - auto& system = GetSystem(); - auto& memory = system.GetMemory(); - { + auto& system = GetSystem(); + auto& memory = system.GetMemory(); std::lock_guard lk(m_devices_mutex); const u32 dest = m_devicechange_hook_request->buffer_out; u32 offset = 0; diff --git a/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp b/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp index 1fa3b58686..dc8cb6ffce 100644 --- a/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp +++ b/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp @@ -183,9 +183,9 @@ IPCReply USB_HIDv5::GetDeviceInfo(USBV5Device& device, const IOCtlRequest& reque for (auto& endpoint : endpoints) { constexpr u8 ENDPOINT_INTERRUPT = 0b11; - constexpr u8 ENDPOINT_IN = 0x80; if (endpoint.bmAttributes == ENDPOINT_INTERRUPT) { + constexpr u8 ENDPOINT_IN = 0x80; const bool is_in_endpoint = (endpoint.bEndpointAddress & ENDPOINT_IN) != 0; AdditionalDeviceData* data = &m_additional_device_data[&device - m_usbv5_devices.data()]; diff --git a/Source/Core/Core/IOS/USB/USB_KBD.cpp b/Source/Core/Core/IOS/USB/USB_KBD.cpp index badfbac4b7..fd46727a39 100644 --- a/Source/Core/Core/IOS/USB/USB_KBD.cpp +++ b/Source/Core/Core/IOS/USB/USB_KBD.cpp @@ -246,12 +246,12 @@ void USB_KBD::Update() { const bool key_pressed_now = IsKeyPressed(static_cast(i)); const bool key_pressed_before = m_old_key_buffer[i]; - u8 key_code = 0; if (key_pressed_now ^ key_pressed_before) { if (key_pressed_now) { + u8 key_code = 0; switch (m_keyboard_layout) { case KBD_LAYOUT_QWERTY: diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index ecde7441ac..8392f2559a 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -1585,9 +1585,9 @@ void NetPlayClient::ThreadFunc() { INFO_LOG_FMT(NETPLAY, "NetPlayClient starting."); - Common::QoSSession qos_session; if (Config::Get(Config::NETPLAY_ENABLE_QOS)) { + Common::QoSSession qos_session; qos_session = Common::QoSSession(m_server); if (qos_session.Successful()) diff --git a/Source/Core/Core/NetworkCaptureLogger.cpp b/Source/Core/Core/NetworkCaptureLogger.cpp index d7da8e2469..445e4c5640 100644 --- a/Source/Core/Core/NetworkCaptureLogger.cpp +++ b/Source/Core/Core/NetworkCaptureLogger.cpp @@ -182,8 +182,7 @@ void PCAPSSLCaptureLogger::LogIPv4(LogType log_type, const u8* data, u16 length, }; Common::EthernetHeader ethernet_header(0x800); - auto mac = Common::StringToMacAddress(Config::Get(Config::MAIN_WIRELESS_MAC)); - if (mac) + if (auto mac = Common::StringToMacAddress(Config::Get(Config::MAIN_WIRELESS_MAC))) { auto& mac_address = (log_type == LogType::Write) ? ethernet_header.source : ethernet_header.destination; diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index 4594f7d6d5..6e06871d26 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -912,8 +912,7 @@ bool Jit64::DoJit(u32 em_address, JitBlock* b, u32 nextPC) if (!js.pairedQuantizeAddresses.contains(js.blockStart)) { // If there are GQRs used but not set, we'll treat those as constant and optimize them - BitSet8 gqr_static = ComputeStaticGQRs(code_block); - if (gqr_static) + if (BitSet8 gqr_static = ComputeStaticGQRs(code_block)) { SwitchToFarCode(); const u8* target = GetCodePtr(); diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp index 4723c1c2cf..a88f75ae4a 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_FloatingPoint.cpp @@ -394,11 +394,9 @@ void Jit64::fmaddXX(UGeckoInstruction inst) RCOpArg Rb; RCOpArg Rc; RCX64Reg Rd; - RCX64Reg xmm2_guard; - RCX64Reg result_xmm_guard; - RCX64Reg Rc_duplicated_guard; if (software_fma) { + RCX64Reg xmm2_guard; xmm2_guard = fpr.Scratch(XMM2); Ra = packed ? fpr.Bind(a, RCMode::Read) : fpr.Use(a, RCMode::Read); Rb = packed ? fpr.Bind(b, RCMode::Read) : fpr.Use(b, RCMode::Read); @@ -406,6 +404,7 @@ void Jit64::fmaddXX(UGeckoInstruction inst) Rd = fpr.Bind(d, single ? RCMode::Write : RCMode::ReadWrite); if (preserve_d && packed) { + RCX64Reg result_xmm_guard; result_xmm_guard = fpr.Scratch(); RegCache::Realize(Ra, Rb, Rc, Rd, xmm2_guard, result_xmm_guard); result_xmm = Gen::X64Reg(result_xmm_guard); @@ -429,6 +428,7 @@ void Jit64::fmaddXX(UGeckoInstruction inst) if (madds_accurate_nans) { + RCX64Reg Rc_duplicated_guard; Rc_duplicated_guard = fpr.Scratch(); RegCache::Realize(Rc_duplicated_guard); Rc_duplicated = Rc_duplicated_guard; diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_LoadStore.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_LoadStore.cpp index 05bd690694..442197794c 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_LoadStore.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_LoadStore.cpp @@ -436,10 +436,9 @@ void Jit64::dcbz(UGeckoInstruction inst) INSTRUCTION_START JITDISABLE(bJITLoadStoreOff); - int a = inst.RA; - int b = inst.RB; - { + int a = inst.RA; + int b = inst.RB; RCOpArg Ra = a ? gpr.Use(a, RCMode::Read) : RCOpArg::Imm32(0); RCOpArg Rb = gpr.Use(b, RCMode::Read); RegCache::Realize(Ra, Rb); @@ -632,10 +631,11 @@ void Jit64::lmw(UGeckoInstruction inst) INSTRUCTION_START JITDISABLE(bJITLoadStoreOff); - int a = inst.RA, d = inst.RD; + int d = inst.RD; // TODO: This doesn't handle rollback on DSI correctly { + int a = inst.RA; RCOpArg Ra = a ? gpr.Use(a, RCMode::Read) : RCOpArg::Imm32(0); RegCache::Realize(Ra); MOV_sum(32, RSCRATCH2, Ra, Imm32((u32)(s32)inst.SIMM_16)); diff --git a/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp b/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp index 6331358359..9c394ed8a0 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit_SystemRegisters.cpp @@ -675,10 +675,10 @@ void Jit64::mcrfs(UGeckoInstruction inst) // Only clear exception bits (but not FEX/VX). mask &= FPSCR_FX | FPSCR_ANY_X; - RCX64Reg scratch_guard; X64Reg scratch; if (mask != 0) { + RCX64Reg scratch_guard; scratch_guard = gpr.Scratch(); RegCache::Realize(scratch_guard); scratch = scratch_guard; diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 890e9975a4..a6182d5f5a 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -391,8 +391,7 @@ void JitBaseBlockCache::LinkBlockExits(JitBlock& block) { if (!e.linkStatus) { - JitBlock* destinationBlock = GetBlockFromStartAddress(e.exitAddress, block.feature_flags); - if (destinationBlock) + if (JitBlock* destinationBlock = GetBlockFromStartAddress(e.exitAddress, block.feature_flags)) { WriteLinkBlock(e, destinationBlock); e.linkStatus = true; diff --git a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp index cccf98a629..a30c55a48a 100644 --- a/Source/Core/Core/PowerPC/PPCSymbolDB.cpp +++ b/Source/Core/Core/PowerPC/PPCSymbolDB.cpp @@ -334,8 +334,7 @@ bool PPCSymbolDB::LoadMap(const Core::CPUThreadGuard& guard, const std::string& { alignment = 0; sscanf(line, "%08x %08x %08x %08x %511s", &address, &size, &vaddress, &offset, name); - char* s = strstr(line, "(entry of "); - if (s) + if (char* s = strstr(line, "(entry of ")) { sscanf(s + 10, "%511s", container); char* s2 = (strchr(container, ')')); @@ -363,8 +362,7 @@ bool PPCSymbolDB::LoadMap(const Core::CPUThreadGuard& guard, const std::string& { alignment = 0; sscanf(line, "%08x %08x %08x %511s", &address, &size, &vaddress, name); - char* s = strstr(line, "(entry of "); - if (s) + if (char* s = strstr(line, "(entry of ")) { sscanf(s + 10, "%511s", container); char* s2 = (strchr(container, ')')); @@ -496,7 +494,6 @@ bool PPCSymbolDB::SaveSymbolMap(const std::string& filename) const // - It's a custom code map format bool PPCSymbolDB::SaveCodeMap(const Core::CPUThreadGuard& guard, const std::string& filename) const { - constexpr int SYMBOL_NAME_LIMIT = 30; File::IOFile f(filename, "w"); if (!f) return false; @@ -526,6 +523,7 @@ bool PPCSymbolDB::SaveCodeMap(const Core::CPUThreadGuard& guard, const std::stri // Write the code for (u32 address = symbol.address; address < next_address; address += 4) { + constexpr int SYMBOL_NAME_LIMIT = 30; const std::string disasm = ppc_debug_interface.Disassemble(&guard, address); f.WriteString(fmt::format("{0:08x} {1:<{2}.{3}} {4}\n", address, symbol.name, SYMBOL_NAME_LIMIT, SYMBOL_NAME_LIMIT, disasm)); diff --git a/Source/Core/Core/PowerPC/SignatureDB/CSVSignatureDB.cpp b/Source/Core/Core/PowerPC/SignatureDB/CSVSignatureDB.cpp index 68010f6570..5cad6bbe26 100644 --- a/Source/Core/Core/PowerPC/SignatureDB/CSVSignatureDB.cpp +++ b/Source/Core/Core/PowerPC/SignatureDB/CSVSignatureDB.cpp @@ -27,11 +27,12 @@ bool CSVSignatureDB::Load(const std::string& file_path) { std::istringstream iss(line); u32 checksum, size; - std::string tab, symbol, object_location, object_name; + std::string tab; iss >> std::hex >> checksum >> std::hex >> size; if (iss && std::getline(iss, tab, '\t')) { + std::string symbol, object_location, object_name; if (std::getline(iss, symbol, '\t') && std::getline(iss, object_location, '\t')) std::getline(iss, object_name); HashSignatureDB::DBFunc func; diff --git a/Source/Core/Core/PowerPC/SignatureDB/SignatureDB.cpp b/Source/Core/Core/PowerPC/SignatureDB/SignatureDB.cpp index b9cec4a2be..254ce2ea84 100644 --- a/Source/Core/Core/PowerPC/SignatureDB/SignatureDB.cpp +++ b/Source/Core/Core/PowerPC/SignatureDB/SignatureDB.cpp @@ -170,8 +170,7 @@ u32 HashSignatureDB::ComputeCodeChecksum(const Core::CPUThreadGuard& guard, u32 u32 op = opcode & 0xFC000000; u32 op2 = 0; u32 op3 = 0; - u32 auxop = op >> 26; - switch (auxop) + switch (u32 auxop = op >> 26) { case 4: // PS instructions op2 = opcode & 0x0000003F; diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index fe20d74ea4..4364be5727 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -420,9 +420,9 @@ static void CompressAndDumpState(Core::System& system, CompressAndDumpState_args const std::string last_state_filename = File::GetUserPath(D_STATESAVES_IDX) + "lastState.sav"; const std::string last_state_dtmname = last_state_filename + ".dtm"; - const std::string dtmname = filename + ".dtm"; { + const std::string dtmname = filename + ".dtm"; std::lock_guard lk(s_save_thread_mutex); // Backup existing state (overwriting an existing backup, if any). diff --git a/Source/Core/Core/WiiUtils.cpp b/Source/Core/Core/WiiUtils.cpp index 2d5a8e4ac3..335b95e683 100644 --- a/Source/Core/Core/WiiUtils.cpp +++ b/Source/Core/Core/WiiUtils.cpp @@ -121,8 +121,7 @@ static bool ImportWAD(IOS::HLE::Kernel& ios, const DiscIO::VolumeWAD& wad, return false; } - const auto old_handle = fs->OpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, path, rw_mode); - if (old_handle) + if (const auto old_handle = fs->OpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, path, rw_mode)) continue; const auto new_handle = fs->CreateAndOpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, path, @@ -977,8 +976,7 @@ static NANDCheckResult CheckNAND(IOS::HLE::Kernel& ios, bool repair) "/title/00010003", "/title/00010004", "/title/00010005", "/title/00010006", "/title/00010007", "/shared2/title"}) { - const auto dir_stats = fs->GetExtendedDirectoryStats(user_path); - if (dir_stats) + if (const auto dir_stats = fs->GetExtendedDirectoryStats(user_path)) { used_clusters_user += dir_stats->used_clusters; used_inodes_user += dir_stats->used_inodes; diff --git a/Source/Core/DiscIO/DirectoryBlob.cpp b/Source/Core/DiscIO/DirectoryBlob.cpp index 7cd7e12def..54a3db7eee 100644 --- a/Source/Core/DiscIO/DirectoryBlob.cpp +++ b/Source/Core/DiscIO/DirectoryBlob.cpp @@ -271,13 +271,13 @@ static bool IsValidDirectoryBlob(const std::string& dol_path, std::string* parti if (File::GetSize(*partition_root + "sys/boot.bin") < 0x20) return false; -#ifdef _WIN32 - constexpr const char* dir_separator = "/\\"; -#else - constexpr char dir_separator = '/'; -#endif if (true_root) { +#ifdef _WIN32 + constexpr const char* dir_separator = "/\\"; +#else + constexpr char dir_separator = '/'; +#endif *true_root = dol_path.substr(0, dol_path.find_last_of(dir_separator, partition_root->size() - 2) + 1); } @@ -462,8 +462,7 @@ DirectoryBlobReader::DirectoryBlobReader( if (partition == m_wrapped_volume->GetGamePartition()) continue; - auto type = m_wrapped_volume->GetPartitionType(partition); - if (type) + if (auto type = m_wrapped_volume->GetPartitionType(partition)) { partitions.emplace_back(DirectoryBlobPartition(m_wrapped_volume.get(), partition, m_is_wii, nullptr, nullptr, this), @@ -657,11 +656,11 @@ void DirectoryBlobReader::SetPartitions(std::vector&& partiti } constexpr u64 STANDARD_UPDATE_PARTITION_ADDRESS = 0x50000; - constexpr u64 STANDARD_GAME_PARTITION_ADDRESS = 0xF800000; u64 partition_address = STANDARD_UPDATE_PARTITION_ADDRESS; u64 offset_in_table = PARTITION_SUBTABLE1_OFFSET; for (size_t i = 0; i < partitions.size(); ++i) { + constexpr u64 STANDARD_GAME_PARTITION_ADDRESS = 0xF800000; if (i == subtable_1_size) offset_in_table = PARTITION_SUBTABLE2_OFFSET; @@ -921,11 +920,9 @@ DirectoryBlobPartition::DirectoryBlobPartition( SetApploader(ExtractNodeToVector(&sys_nodes, &apploader, blob), "apploader"); FSTBuilderNode dol_node{"main.dol", 0, {}}; - const auto dol_offset = GetBootDOLOffset(*volume, partition); - if (dol_offset) + if (const auto dol_offset = GetBootDOLOffset(*volume, partition)) { - const auto dol_size = GetBootDOLSize(*volume, partition, *dol_offset); - if (dol_size) + if (const auto dol_size = GetBootDOLSize(*volume, partition, *dol_offset)) { std::vector dol_contents; dol_contents.emplace_back( diff --git a/Source/Core/DiscIO/DiscUtils.cpp b/Source/Core/DiscIO/DiscUtils.cpp index afd22117c6..60901d0ecf 100644 --- a/Source/Core/DiscIO/DiscUtils.cpp +++ b/Source/Core/DiscIO/DiscUtils.cpp @@ -168,11 +168,9 @@ u64 GetBiggestReferencedOffset(const Volume& volume, const std::vector dol_offset = GetBootDOLOffset(volume, partition); - if (dol_offset) + if (const std::optional dol_offset = GetBootDOLOffset(volume, partition)) { - const std::optional dol_size = GetBootDOLSize(volume, partition, *dol_offset); - if (dol_size) + if (const std::optional dol_size = GetBootDOLSize(volume, partition, *dol_offset)) { const u64 offset = volume.PartitionOffsetToRawOffset(*dol_offset + *dol_size, partition); biggest_offset = std::max(biggest_offset, offset); @@ -187,8 +185,7 @@ u64 GetBiggestReferencedOffset(const Volume& volume, const std::vectorGetRoot()); const u64 offset = volume.PartitionOffsetToRawOffset(offset_in_partition, partition); diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp index 4090a9882d..a2e121de0e 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/FileSystemGCWii.cpp @@ -325,12 +325,11 @@ std::unique_ptr FileSystemGCWii::FindFileInfo(std::string_view path, if (child.NameCaseInsensitiveEquals(name)) { // A match is found. The rest of the path is passed on to finish the search. - std::unique_ptr result = FindFileInfo(rest_of_path, child); - - // If the search wasn't successful, the loop continues, just in case there's a second - // file info that matches searching_for (which probably won't happen in practice) - if (result) + if (std::unique_ptr result = FindFileInfo(rest_of_path, child)) return result; + + // The search wasn't successful, the loop continues, just in case there's a second + // file info that matches searching_for (which probably won't happen in practice) } } diff --git a/Source/Core/DiscIO/NANDImporter.cpp b/Source/Core/DiscIO/NANDImporter.cpp index 8ab09da8b3..637651f8f9 100644 --- a/Source/Core/DiscIO/NANDImporter.cpp +++ b/Source/Core/DiscIO/NANDImporter.cpp @@ -90,11 +90,10 @@ bool NANDImporter::ReadNANDBin(const std::string& path_to_bin, bool NANDImporter::FindSuperblock() { - constexpr size_t NAND_SUPERBLOCK_START = 0x1fc00000; - // There are 16 superblocks, choose the highest/newest version for (int i = 0; i < 16; i++) { + constexpr size_t NAND_SUPERBLOCK_START = 0x1fc00000; auto superblock = std::make_unique(); std::memcpy(superblock.get(), &m_nand[NAND_SUPERBLOCK_START + i * sizeof(NANDSuperblock)], sizeof(NANDSuperblock)); diff --git a/Source/Core/DiscIO/RiivolutionParser.cpp b/Source/Core/DiscIO/RiivolutionParser.cpp index 656cd20697..b7b273d2d9 100644 --- a/Source/Core/DiscIO/RiivolutionParser.cpp +++ b/Source/Core/DiscIO/RiivolutionParser.cpp @@ -87,8 +87,7 @@ std::optional ParseString(std::string_view xml, std::string xml_path) return std::nullopt; const std::string default_root = wiidisc.attribute("root").as_string(); - const auto id = wiidisc.child("id"); - if (id) + if (const auto id = wiidisc.child("id")) { for (const auto& attribute : id.attributes()) { @@ -113,8 +112,7 @@ std::optional ParseString(std::string_view xml, std::string xml_path) } } - const auto options = wiidisc.child("options"); - if (options) + if (const auto options = wiidisc.child("options")) { for (const auto& section_node : options.children("section")) { diff --git a/Source/Core/DiscIO/RiivolutionPatcher.cpp b/Source/Core/DiscIO/RiivolutionPatcher.cpp index 8c54968c35..baa200f9d7 100644 --- a/Source/Core/DiscIO/RiivolutionPatcher.cpp +++ b/Source/Core/DiscIO/RiivolutionPatcher.cpp @@ -50,8 +50,7 @@ FileDataLoaderHostFS::FileDataLoaderHostFS(std::string sd_root, const std::strin // m_patch_root with it. if (!patch_root.empty()) { - auto r = MakeAbsoluteFromRelative(patch_root); - if (r) + if (auto r = MakeAbsoluteFromRelative(patch_root)) m_patch_root = std::move(*r); } } @@ -405,8 +404,7 @@ static DiscIO::FSTBuilderNode* FindFilenameNodeInFST(std::string_view filename, { if (node.IsFolder()) { - DiscIO::FSTBuilderNode* result = FindFilenameNodeInFST(filename, node.GetFolderContent()); - if (result) + if (DiscIO::FSTBuilderNode* result = FindFilenameNodeInFST(filename, node.GetFolderContent())) return result; } else if (Common::CaseInsensitiveEquals(node.m_filename, filename)) @@ -438,8 +436,7 @@ static void ApplyFilePatchToFST(const Patch& patch, const File& file, else { // Otherwise we want to patch the first file in the FST that matches that filename. - DiscIO::FSTBuilderNode* node = FindFilenameNodeInFST(file.m_disc, *fst); - if (node) + if (DiscIO::FSTBuilderNode* node = FindFilenameNodeInFST(file.m_disc, *fst)) ApplyPatchToFile(patch, file, node); } } @@ -666,8 +663,7 @@ std::optional ExtractSavegameRedirect(std::span r if (!patch.m_savegame_patches.empty()) { const auto& save_patch = patch.m_savegame_patches[0]; - auto resolved = patch.m_file_data_loader->ResolveSavegameRedirectPath(save_patch.m_external); - if (resolved) + if (auto resolved = patch.m_file_data_loader->ResolveSavegameRedirectPath(save_patch.m_external)) return SavegameRedirect{std::move(*resolved), save_patch.m_clone}; return std::nullopt; } diff --git a/Source/Core/DiscIO/Volume.cpp b/Source/Core/DiscIO/Volume.cpp index b6d84254f0..d9263b7e28 100644 --- a/Source/Core/DiscIO/Volume.cpp +++ b/Source/Core/DiscIO/Volume.cpp @@ -136,12 +136,10 @@ std::unique_ptr CreateWAD(const std::string& path) std::unique_ptr CreateVolume(std::unique_ptr reader) { - std::unique_ptr disc = TryCreateDisc(reader); - if (disc) + if (std::unique_ptr disc = TryCreateDisc(reader)) return disc; - std::unique_ptr wad = TryCreateWAD(reader); - if (wad) + if (std::unique_ptr wad = TryCreateWAD(reader)) return wad; return nullptr; diff --git a/Source/Core/DiscIO/VolumeDisc.cpp b/Source/Core/DiscIO/VolumeDisc.cpp index b32ddc6d17..1f85cbc780 100644 --- a/Source/Core/DiscIO/VolumeDisc.cpp +++ b/Source/Core/DiscIO/VolumeDisc.cpp @@ -103,21 +103,18 @@ void VolumeDisc::AddGamePartitionToSyncHash(Common::SHA1::Context* context) cons partition); // Boot DOL (may be missing if this is a Datel disc) - const std::optional dol_offset = GetBootDOLOffset(*this, partition); - if (dol_offset) + if (const std::optional dol_offset = GetBootDOLOffset(*this, partition)) { ReadAndAddToSyncHash(context, *dol_offset, GetBootDOLSize(*this, partition, *dol_offset).value_or(0), partition); } // File system - const std::optional fst_offset = GetFSTOffset(*this, partition); - if (fst_offset) + if (const std::optional fst_offset = GetFSTOffset(*this, partition)) ReadAndAddToSyncHash(context, *fst_offset, GetFSTSize(*this, partition).value_or(0), partition); // opening.bnr (name and banner) - const FileSystem* file_system = GetFileSystem(partition); - if (file_system) + if (const FileSystem* file_system = GetFileSystem(partition)) { std::unique_ptr file_info = file_system->FindFileInfo("opening.bnr"); if (file_info && !file_info->IsDirectory()) diff --git a/Source/Core/DiscIO/VolumeVerifier.cpp b/Source/Core/DiscIO/VolumeVerifier.cpp index efbe129a5f..c9c07ffec4 100644 --- a/Source/Core/DiscIO/VolumeVerifier.cpp +++ b/Source/Core/DiscIO/VolumeVerifier.cpp @@ -448,8 +448,7 @@ std::vector VolumeVerifier::CheckPartitions() std::vector types; for (const Partition& partition : partitions) { - const std::optional type = m_volume.GetPartitionType(partition); - if (type) + if (const std::optional type = m_volume.GetPartitionType(partition)) types.emplace_back(*type); } @@ -656,8 +655,7 @@ bool VolumeVerifier::CheckPartition(const Partition& partition) if (!has_correct_ios && tmd.IsValid()) { - std::unique_ptr file_info = filesystem->FindFileInfo("_sys"); - if (file_info) + if (std::unique_ptr file_info = filesystem->FindFileInfo("_sys")) { const std::string ios_ver_str = std::to_string(ios_ver); const std::string correct_ios = diff --git a/Source/Core/DiscIO/VolumeWii.cpp b/Source/Core/DiscIO/VolumeWii.cpp index eca23fb4f9..b5ce0e45c2 100644 --- a/Source/Core/DiscIO/VolumeWii.cpp +++ b/Source/Core/DiscIO/VolumeWii.cpp @@ -449,11 +449,11 @@ bool VolumeWii::CheckBlockIntegrity(u64 block_index, const u8* encrypted_data, } HashBlock hashes; - u8 cluster_data_buffer[BLOCK_DATA_SIZE]; const u8* cluster_data; if (m_has_encryption) { + u8 cluster_data_buffer[BLOCK_DATA_SIZE]; Common::AES::Context* aes_context = partition_details.key->get(); if (!aes_context) return false; diff --git a/Source/Core/DolphinQt/CheatSearchFactoryWidget.cpp b/Source/Core/DolphinQt/CheatSearchFactoryWidget.cpp index 3b5ddcb1c1..fcb255f209 100644 --- a/Source/Core/DolphinQt/CheatSearchFactoryWidget.cpp +++ b/Source/Core/DolphinQt/CheatSearchFactoryWidget.cpp @@ -198,7 +198,7 @@ void CheatSearchFactoryWidget::OnNewSearchClicked() bool aligned = m_data_type_aligned->isChecked(); auto data_type = m_data_type_dropdown->currentData().value(); - auto session = Cheats::MakeSession(std::move(memory_ranges), address_space, aligned, data_type); - if (session) + if (auto session = + Cheats::MakeSession(std::move(memory_ranges), address_space, aligned, data_type)) emit NewSessionCreated(*session); } diff --git a/Source/Core/DolphinQt/CheatSearchWidget.cpp b/Source/Core/DolphinQt/CheatSearchWidget.cpp index 3a4c024c97..408d66ffd9 100644 --- a/Source/Core/DolphinQt/CheatSearchWidget.cpp +++ b/Source/Core/DolphinQt/CheatSearchWidget.cpp @@ -90,8 +90,7 @@ void CheatSearchWidget::CreateWidgets() QLabel* session_info_label = new QLabel(); { QString ranges; - size_t range_count = m_session->GetMemoryRangeCount(); - switch (range_count) + switch (size_t range_count = m_session->GetMemoryRangeCount()) { case 1: { @@ -460,9 +459,8 @@ void CheatSearchWidget::OnResetClicked() void CheatSearchWidget::OnAddressTableItemChanged(QTableWidgetItem* item) { const u32 address = item->data(ADDRESS_TABLE_ADDRESS_ROLE).toUInt(); - const int column = item->column(); - switch (column) + switch (item->column()) { case ADDRESS_TABLE_COLUMN_INDEX_DESCRIPTION: { @@ -537,8 +535,7 @@ void CheatSearchWidget::GenerateARCodes() for (auto* const item : m_address_table->selectedItems()) { const u32 index = item->data(ADDRESS_TABLE_RESULT_INDEX_ROLE).toUInt(); - auto result = Cheats::GenerateActionReplayCode(*m_session, index); - if (result) + if (auto result = Cheats::GenerateActionReplayCode(*m_session, index)) { emit ActionReplayCodeGenerated(*result); had_success = true; diff --git a/Source/Core/DolphinQt/CheatsManager.cpp b/Source/Core/DolphinQt/CheatsManager.cpp index 53f051785c..9737f1758b 100644 --- a/Source/Core/DolphinQt/CheatsManager.cpp +++ b/Source/Core/DolphinQt/CheatsManager.cpp @@ -185,8 +185,7 @@ void CheatsManager::OnNewSessionCreated(const Cheats::CheatSearchSessionBase& se void CheatsManager::OnTabCloseRequested(int index) { - auto* w = m_tab_widget->widget(index); - if (w) + if (auto* w = m_tab_widget->widget(index)) w->deleteLater(); } diff --git a/Source/Core/DolphinQt/Config/FilesystemWidget.cpp b/Source/Core/DolphinQt/Config/FilesystemWidget.cpp index 53b447fc47..24b1583fcb 100644 --- a/Source/Core/DolphinQt/Config/FilesystemWidget.cpp +++ b/Source/Core/DolphinQt/Config/FilesystemWidget.cpp @@ -179,8 +179,7 @@ void FilesystemWidget::PopulateDirectory(int partition_id, QStandardItem* root, root->setText(text); - const DiscIO::FileSystem* const file_system = m_volume->GetFileSystem(partition); - if (file_system) + if (const DiscIO::FileSystem* const file_system = m_volume->GetFileSystem(partition)) PopulateDirectory(partition_id, root, file_system->GetRoot()); } diff --git a/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp b/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp index d548724c7e..fc24684afb 100644 --- a/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp +++ b/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp @@ -176,8 +176,7 @@ void GamecubeControllersWidget::LoadSettings(Core::State state) { const SerialInterface::SIDevices si_device = Config::Get(Config::GetInfoForSIDevice(static_cast(i))); - const std::optional gc_index = ToGCMenuIndex(si_device); - if (gc_index) + if (const std::optional gc_index = ToGCMenuIndex(si_device)) { SignalBlocking(m_gc_controller_boxes[i])->setCurrentIndex(*gc_index); m_gc_controller_boxes[i]->setEnabled(NetPlay::IsNetPlayRunning() ? !running : true); diff --git a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp index f70b01ef6a..d70363c4ed 100644 --- a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp @@ -316,9 +316,9 @@ void EnhancementsWidget::LoadPPShaders(StereoMode stereo_mode) tr("%1 doesn't support this feature.") .arg(tr(g_video_backend->GetDisplayName().c_str()))); - VideoCommon::PostProcessingConfiguration pp_shader; if (selected_shader != "" && supports_postprocessing) { + VideoCommon::PostProcessingConfiguration pp_shader; pp_shader.LoadShader(selected_shader); m_configure_pp_effect->setEnabled(pp_shader.HasOptions()); } @@ -497,9 +497,9 @@ void EnhancementsWidget::SaveSettings() "" : m_pp_effect->currentText().toStdString()); - VideoCommon::PostProcessingConfiguration pp_shader; if (Config::Get(Config::GFX_ENHANCE_POST_SHADER) != "") { + VideoCommon::PostProcessingConfiguration pp_shader; pp_shader.LoadShader(Config::Get(Config::GFX_ENHANCE_POST_SHADER)); m_configure_pp_effect->setEnabled(pp_shader.HasOptions()); } diff --git a/Source/Core/DolphinQt/Config/PropertiesDialog.cpp b/Source/Core/DolphinQt/Config/PropertiesDialog.cpp index 86be3e8c3c..c857cad609 100644 --- a/Source/Core/DolphinQt/Config/PropertiesDialog.cpp +++ b/Source/Core/DolphinQt/Config/PropertiesDialog.cpp @@ -77,8 +77,7 @@ PropertiesDialog::PropertiesDialog(QWidget* parent, const UICommon::GameFile& ga if (game.GetPlatform() != DiscIO::Platform::ELFOrDOL) { - std::shared_ptr volume = DiscIO::CreateVolume(game.GetFilePath()); - if (volume) + if (std::shared_ptr volume = DiscIO::CreateVolume(game.GetFilePath())) { VerifyWidget* verify = new VerifyWidget(volume); tab_widget->addTab(GetWrappedWidget(verify, this, padding_width, padding_height), diff --git a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp index be1eb0a4b9..e16d5926e5 100644 --- a/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeViewWidget.cpp @@ -70,10 +70,10 @@ private: painter->setClipRect(option.rect); painter->setPen(m_parent->palette().text().color()); - constexpr u32 x_offset_in_branch_for_vertical_line = 10; const u32 addr = m_parent->AddressForRow(index.row()); for (const CodeViewBranch& branch : m_parent->m_branches) { + constexpr u32 x_offset_in_branch_for_vertical_line = 10; const int y_center = option.rect.top() + option.rect.height() / 2; const int x_left = option.rect.left() + WIDTH_PER_BRANCH_ARROW * branch.indentation; const int x_right = x_left + x_offset_in_branch_for_vertical_line; diff --git a/Source/Core/DolphinQt/Debugger/CodeWidget.cpp b/Source/Core/DolphinQt/Debugger/CodeWidget.cpp index 36d3d92284..a426d0e222 100644 --- a/Source/Core/DolphinQt/Debugger/CodeWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/CodeWidget.cpp @@ -401,9 +401,8 @@ void CodeWidget::UpdateFunctionCalls(const Common::Symbol* symbol) for (const auto& call : symbol->calls) { const u32 addr = call.function; - const Common::Symbol* const call_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr); - if (call_symbol) + if (const Common::Symbol* const call_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr)) { const QString name = QString::fromStdString(fmt::format("> {} ({:08x})", call_symbol->name, addr)); @@ -426,9 +425,8 @@ void CodeWidget::UpdateFunctionCallers(const Common::Symbol* symbol) for (const auto& caller : symbol->callers) { const u32 addr = caller.call_address; - const Common::Symbol* const caller_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr); - if (caller_symbol) + if (const Common::Symbol* const caller_symbol = m_ppc_symbol_db.GetSymbolFromAddr(addr)) { const QString name = QString::fromStdString(fmt::format("< {} ({:08x})", caller_symbol->name, addr)); @@ -516,8 +514,8 @@ void CodeWidget::StepOut() clock::time_point timeout = clock::now() + std::chrono::seconds(5); auto& power_pc = m_system.GetPowerPC(); - auto& ppc_state = power_pc.GetPPCState(); { + auto& ppc_state = power_pc.GetPPCState(); Core::CPUThreadGuard guard(m_system); PowerPC::CoreMode old_mode = power_pc.GetMode(); diff --git a/Source/Core/DolphinQt/GameList/GameList.cpp b/Source/Core/DolphinQt/GameList/GameList.cpp index f1d69613a3..3ab7c19ca4 100644 --- a/Source/Core/DolphinQt/GameList/GameList.cpp +++ b/Source/Core/DolphinQt/GameList/GameList.cpp @@ -187,11 +187,11 @@ void GameList::MakeListView() if (!Settings::GetQSettings().contains(QStringLiteral("tableheader/state"))) m_list->sortByColumn(static_cast(GameListModel::Column::Title), Qt::AscendingOrder); - const auto SetResizeMode = [&hor_header](const GameListModel::Column column, - const QHeaderView::ResizeMode mode) { - hor_header->setSectionResizeMode(static_cast(column), mode); - }; { + const auto SetResizeMode = [&hor_header](const GameListModel::Column column, + const QHeaderView::ResizeMode mode) { + hor_header->setSectionResizeMode(static_cast(column), mode); + }; using Column = GameListModel::Column; using Mode = QHeaderView::ResizeMode; SetResizeMode(Column::Platform, Mode::Fixed); @@ -1021,8 +1021,6 @@ void GameList::OnSectionResized(int index, int, int) { auto* hor_header = m_list->horizontalHeader(); - std::vector sections; - const int vis_index = hor_header->visualIndex(index); const int col_count = hor_header->count() - hor_header->hiddenSectionCount(); @@ -1040,6 +1038,7 @@ void GameList::OnSectionResized(int index, int, int) if (!last) { + std::vector sections; for (int i = 0; i < vis_index; i++) { const int logical_index = hor_header->logicalIndex(i); diff --git a/Source/Core/DolphinQt/GameList/GameListModel.cpp b/Source/Core/DolphinQt/GameList/GameListModel.cpp index c70a870c23..c64de13b03 100644 --- a/Source/Core/DolphinQt/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt/GameList/GameListModel.cpp @@ -106,13 +106,12 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const // For natural sorting, pad all numbers to the same length. if (SORT_ROLE == role) { - constexpr int MAX_NUMBER_LENGTH = 10; - const QRegularExpression rx(QStringLiteral("\\d+")); QRegularExpressionMatch match; int pos = 0; while ((match = rx.match(name, pos)).hasMatch()) { + constexpr int MAX_NUMBER_LENGTH = 10; pos = match.capturedStart(); name.replace(pos, match.capturedLength(), match.captured().rightJustified(MAX_NUMBER_LENGTH)); diff --git a/Source/Core/DolphinQt/GameList/GameTracker.cpp b/Source/Core/DolphinQt/GameList/GameTracker.cpp index 9428729997..2b0a64afbf 100644 --- a/Source/Core/DolphinQt/GameList/GameTracker.cpp +++ b/Source/Core/DolphinQt/GameList/GameTracker.cpp @@ -356,8 +356,7 @@ void GameTracker::LoadGame(const QString& path) if (!DiscIO::ShouldHideFromGameList(converted_path)) { bool cache_changed = false; - auto game = m_cache.AddOrGet(converted_path, &cache_changed); - if (game) + if (auto game = m_cache.AddOrGet(converted_path, &cache_changed)) emit GameLoaded(std::move(game)); if (cache_changed && !m_refresh_in_progress) m_cache.Save(); diff --git a/Source/Core/DolphinQt/HotkeyScheduler.cpp b/Source/Core/DolphinQt/HotkeyScheduler.cpp index 232f41c2f8..08fd21412c 100644 --- a/Source/Core/DolphinQt/HotkeyScheduler.cpp +++ b/Source/Core/DolphinQt/HotkeyScheduler.cpp @@ -80,9 +80,6 @@ static bool IsHotkey(int id, bool held = false) static void HandleFrameStepHotkeys() { - constexpr int MAX_FRAME_STEP_DELAY = 60; - constexpr int FRAME_STEP_DELAY = 30; - static int frame_step_count = 0; static int frame_step_delay = 1; static int frame_step_delay_count = 0; @@ -96,6 +93,7 @@ static void HandleFrameStepHotkeys() if (IsHotkey(HK_FRAME_ADVANCE_DECREASE_SPEED)) { + constexpr int MAX_FRAME_STEP_DELAY = 60; frame_step_delay = std::min(frame_step_delay + 1, MAX_FRAME_STEP_DELAY); return; } @@ -108,6 +106,7 @@ static void HandleFrameStepHotkeys() if (IsHotkey(HK_FRAME_ADVANCE, true)) { + constexpr int FRAME_STEP_DELAY = 30; if (frame_step_delay_count < frame_step_delay && frame_step_hold) frame_step_delay_count++; diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index a02f26b7a9..640619e6c1 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -846,8 +846,7 @@ void MainWindow::Play(const std::optional& savestate_path) } else { - std::shared_ptr selection = m_game_list->GetSelectedGame(); - if (selection) + if (std::shared_ptr selection = m_game_list->GetSelectedGame()) { StartGame(selection->GetFilePath(), ScanForSecondDisc::Yes, std::make_unique(savestate_path, DeleteSavestateAfterBoot::No)); @@ -1961,8 +1960,7 @@ void MainWindow::OnActivateChat() void MainWindow::OnRequestGolfControl() { - auto client = Settings::Instance().GetNetPlayClient(); - if (client) + if (auto client = Settings::Instance().GetNetPlayClient()) client->RequestGolfControl(); } diff --git a/Source/Core/DolphinQt/NANDRepairDialog.cpp b/Source/Core/DolphinQt/NANDRepairDialog.cpp index f88f666740..53a20e16a6 100644 --- a/Source/Core/DolphinQt/NANDRepairDialog.cpp +++ b/Source/Core/DolphinQt/NANDRepairDialog.cpp @@ -48,10 +48,10 @@ NANDRepairDialog::NANDRepairDialog(const WiiUtils::NANDCheckResult& result, QWid main_layout->addWidget(warning_label); std::string title_listings; - Core::TitleDatabase title_db; const DiscIO::Language language = SConfig::GetInstance().GetCurrentLanguage(true); for (const u64 title_id : result.titles_to_remove) { + Core::TitleDatabase title_db; title_listings += fmt::format("{:016x}", title_id); const std::string database_name = title_db.GetChannelName(title_id, language); diff --git a/Source/Core/DolphinQt/NetPlay/ChunkedProgressDialog.cpp b/Source/Core/DolphinQt/NetPlay/ChunkedProgressDialog.cpp index 18ba1a2d3c..a3a5883325 100644 --- a/Source/Core/DolphinQt/NetPlay/ChunkedProgressDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/ChunkedProgressDialog.cpp @@ -141,9 +141,7 @@ void ChunkedProgressDialog::SetProgress(const int pid, const u64 progress) void ChunkedProgressDialog::reject() { - auto server = Settings::Instance().GetNetPlayServer(); - - if (server) + if (auto server = Settings::Instance().GetNetPlayServer()) server->AbortGameStart(); QDialog::reject(); diff --git a/Source/Core/DolphinQt/NetPlay/GameDigestDialog.cpp b/Source/Core/DolphinQt/NetPlay/GameDigestDialog.cpp index 6ca4ec378d..75f949e604 100644 --- a/Source/Core/DolphinQt/NetPlay/GameDigestDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/GameDigestDialog.cpp @@ -164,9 +164,7 @@ void GameDigestDialog::SetResult(int pid, const std::string& result) void GameDigestDialog::reject() { - auto server = Settings::Instance().GetNetPlayServer(); - - if (server) + if (auto server = Settings::Instance().GetNetPlayServer()) server->AbortGameDigest(); QDialog::reject(); diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp index d502e8943e..be0e6e55e4 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlayBrowser.cpp @@ -199,9 +199,7 @@ void NetPlayBrowser::RefreshLoop() NetPlayIndex client; - auto entries = client.List(filters); - - if (entries) + if (auto entries = client.List(filters)) { emit UpdateListRequested(std::move(*entries)); } diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp index c02946d48f..32b1b7bc44 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp @@ -367,8 +367,7 @@ void NetPlayDialog::ConnectWidgets() const auto hia_function = [this](bool enable) { if (m_host_input_authority != enable) { - auto server = Settings::Instance().GetNetPlayServer(); - if (server) + if (auto server = Settings::Instance().GetNetPlayServer()) server->SetHostInputAuthority(enable); } }; @@ -881,9 +880,7 @@ void NetPlayDialog::OnMsgStartGame() } QueueOnObject(this, [this] { - auto client = Settings::Instance().GetNetPlayClient(); - - if (client) + if (auto client = Settings::Instance().GetNetPlayClient()) { if (auto game = FindGameFile(m_current_game_identifier)) client->StartGame(game->GetFilePath()); @@ -1047,8 +1044,7 @@ void NetPlayDialog::OnTtlDetermined(u8 ttl) bool NetPlayDialog::IsRecording() { - std::optional is_recording = RunOnObject(m_record_input_action, &QAction::isChecked); - if (is_recording) + if (std::optional is_recording = RunOnObject(m_record_input_action, &QAction::isChecked)) return *is_recording; return false; } @@ -1274,7 +1270,6 @@ void NetPlayDialog::SetChunkedProgress(const int pid, const u64 progress) void NetPlayDialog::SetHostWiiSyncData(std::vector titles, std::string redirect_folder) { - auto client = Settings::Instance().GetNetPlayClient(); - if (client) + if (auto client = Settings::Instance().GetNetPlayClient()) client->SetWiiSyncData(nullptr, std::move(titles), std::move(redirect_folder)); } diff --git a/Source/Core/DolphinQt/RenderWidget.cpp b/Source/Core/DolphinQt/RenderWidget.cpp index d88a17e3d3..4f0c399ed2 100644 --- a/Source/Core/DolphinQt/RenderWidget.cpp +++ b/Source/Core/DolphinQt/RenderWidget.cpp @@ -530,11 +530,10 @@ void RenderWidget::PassEventToPresenter(const QEvent* event) const u32 key = static_cast(key_event->key() & 0x1FF); const char* chars = nullptr; - QByteArray utf8; if (is_down) { - utf8 = key_event->text().toUtf8(); + QByteArray utf8 = key_event->text().toUtf8(); if (utf8.size()) chars = utf8.constData(); diff --git a/Source/Core/DolphinQt/RiivolutionBootWidget.cpp b/Source/Core/DolphinQt/RiivolutionBootWidget.cpp index 29b5af0a1f..b4799c4751 100644 --- a/Source/Core/DolphinQt/RiivolutionBootWidget.cpp +++ b/Source/Core/DolphinQt/RiivolutionBootWidget.cpp @@ -161,8 +161,7 @@ void RiivolutionBootWidget::OpenXML() } auto root = FindRoot(p); - const auto config = LoadConfigXML(root); - if (config) + if (const auto config = LoadConfigXML(root)) DiscIO::Riivolution::ApplyConfigDefaults(&*parsed, *config); MakeGUIForParsedFile(p, std::move(root), *parsed); } diff --git a/Source/Core/DolphinQt/Settings/GameCubePane.cpp b/Source/Core/DolphinQt/Settings/GameCubePane.cpp index 806e0c7840..77a6b0643b 100644 --- a/Source/Core/DolphinQt/Settings/GameCubePane.cpp +++ b/Source/Core/DolphinQt/Settings/GameCubePane.cpp @@ -815,8 +815,7 @@ void GameCubePane::SaveSettings() m_gba_rom_edits[i]->text().toStdString()); } - auto server = Settings::Instance().GetNetPlayServer(); - if (server) + if (auto server = Settings::Instance().GetNetPlayServer()) server->SetGBAConfig(server->GetGBAConfig(), true); } #endif diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp index 2e2adab6c0..38ae371669 100644 --- a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp +++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp @@ -154,8 +154,7 @@ Token Lexer::NextToken() if (it == expr.end()) return Token(TOK_EOF); - char c = *it++; - switch (c) + switch (char c = *it++) { case ' ': case '\t': diff --git a/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp b/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp index 720ea82735..3886f304d5 100644 --- a/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp +++ b/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp @@ -305,17 +305,14 @@ Device::Input* DeviceContainer::FindInput(std::string_view name, const Device* d { if (def_dev) { - Device::Input* const inp = def_dev->FindInput(name); - if (inp) + if (Device::Input* const inp = def_dev->FindInput(name)) return inp; } std::lock_guard lk(m_devices_mutex); for (const auto& d : m_devices) { - Device::Input* const i = d->FindInput(name); - - if (i) + if (Device::Input* const i = d->FindInput(name)) return i; } diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index feb1f8f4ce..0ccebc9288 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -304,9 +304,8 @@ std::unique_ptr CreateInputBackend(ControllerInterface* co void InputBackend::OpenAndAddDevice(int index) { SDL_GameController* gc = SDL_GameControllerOpen(index); - SDL_Joystick* js = SDL_JoystickOpen(index); - if (js) + if (SDL_Joystick* js = SDL_JoystickOpen(index)) { if (SDL_JoystickNumButtons(js) > 255 || SDL_JoystickNumAxes(js) > 255 || SDL_JoystickNumHats(js) > 255 || SDL_JoystickNumBalls(js) > 255) diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp index 01cfcd2f92..78c4440eaa 100644 --- a/Source/Core/InputCommon/GCAdapter.cpp +++ b/Source/Core/InputCommon/GCAdapter.cpp @@ -279,8 +279,7 @@ static void WriteThreadFunc() { s_write_happened.Wait(); - const int write_size = s_controller_write_payload_size.load(); - if (write_size) + if (const int write_size = s_controller_write_payload_size.load()) { #if GCADAPTER_USE_LIBUSB_IMPLEMENTATION const int error = @@ -953,10 +952,10 @@ void Output(int chan, u8 rumble_command) s_port_states[chan].controller_type != ControllerType::Wireless) { s_controller_rumble[chan] = rumble_command; - std::array rumble = { - 0x11, s_controller_rumble[0], s_controller_rumble[1], s_controller_rumble[2], - s_controller_rumble[3]}; { + std::array rumble = { + 0x11, s_controller_rumble[0], s_controller_rumble[1], s_controller_rumble[2], + s_controller_rumble[3]}; #if GCADAPTER_USE_ANDROID_IMPLEMENTATION std::lock_guard lk(s_write_mutex); #endif diff --git a/Source/Core/InputCommon/InputProfile.cpp b/Source/Core/InputCommon/InputProfile.cpp index 0d439c48e1..9fec63408f 100644 --- a/Source/Core/InputCommon/InputProfile.cpp +++ b/Source/Core/InputCommon/InputProfile.cpp @@ -127,8 +127,7 @@ void ProfileCycler::CycleProfile(CycleDirection cycle_direction, InputConfig* de } const std::string profile = GetProfile(cycle_direction, profile_index, profiles); - auto* controller = device_configuration->GetController(controller_index); - if (controller) + if (auto* controller = device_configuration->GetController(controller_index)) { UpdateToProfile(profile, controller, device_configuration); } @@ -166,8 +165,7 @@ void ProfileCycler::CycleProfileForGame(CycleDirection cycle_direction, const std::string profile = GetProfile(cycle_direction, profile_index, profiles_for_game); - auto* controller = device_configuration->GetController(controller_index); - if (controller) + if (auto* controller = device_configuration->GetController(controller_index)) { UpdateToProfile(profile, controller, device_configuration); } diff --git a/Source/Core/UICommon/AutoUpdate.cpp b/Source/Core/UICommon/AutoUpdate.cpp index e1d6b7732c..bd92ec55e7 100644 --- a/Source/Core/UICommon/AutoUpdate.cpp +++ b/Source/Core/UICommon/AutoUpdate.cpp @@ -168,8 +168,7 @@ static std::string GetPlatformID() static std::string GetUpdateServerUrl() { - auto server_url = std::getenv("DOLPHIN_UPDATE_SERVER_URL"); - if (server_url) + if (auto server_url = std::getenv("DOLPHIN_UPDATE_SERVER_URL")) return server_url; return "https://dolphin-emu.org"; } diff --git a/Source/Core/UICommon/CommandLineParse.cpp b/Source/Core/UICommon/CommandLineParse.cpp index a37f0f2561..da7c301727 100644 --- a/Source/Core/UICommon/CommandLineParse.cpp +++ b/Source/Core/UICommon/CommandLineParse.cpp @@ -51,8 +51,7 @@ public: std::getline(buffer, section, '.'); std::getline(buffer, key, '='); std::getline(buffer, value, '='); - std::optional system = Config::GetSystemFromName(system_str); - if (system) + if (std::optional system = Config::GetSystemFromName(system_str)) { m_values.emplace_back( Config::Location{std::move(*system), std::move(section), std::move(key)}, diff --git a/Source/Core/UICommon/GameFile.cpp b/Source/Core/UICommon/GameFile.cpp index 7603463138..85fbc41b80 100644 --- a/Source/Core/UICommon/GameFile.cpp +++ b/Source/Core/UICommon/GameFile.cpp @@ -158,8 +158,7 @@ GameFile::GameFile(std::string path) : m_file_path(std::move(path)) if (!IsValid() && GetExtension() == ".json") { - auto descriptor = DiscIO::ParseGameModDescriptorFile(m_file_path); - if (descriptor) + if (auto descriptor = DiscIO::ParseGameModDescriptorFile(m_file_path)) { GameFile proxy(descriptor->base_file); if (proxy.IsValid()) @@ -691,8 +690,7 @@ Common::SHA1::Digest GameFile::GetSyncHash() const } else if (m_blob_type == DiscIO::BlobType::MOD_DESCRIPTOR) { - auto descriptor = DiscIO::ParseGameModDescriptorFile(m_file_path); - if (descriptor) + if (auto descriptor = DiscIO::ParseGameModDescriptorFile(m_file_path)) { GameFile proxy(descriptor->base_file); if (proxy.IsValid()) diff --git a/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp b/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp index 0f81db9aaa..10e2af5e79 100644 --- a/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/D3D/D3DNativeVertexFormat.cpp @@ -143,8 +143,7 @@ D3DVertexFormat::D3DVertexFormat(const PortableVertexDeclaration& vtx_decl) D3DVertexFormat::~D3DVertexFormat() { - ID3D11InputLayout* layout = m_layout.load(); - if (layout) + if (ID3D11InputLayout* layout = m_layout.load()) layout->Release(); } diff --git a/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp b/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp index 5929788b03..297b87415d 100644 --- a/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp +++ b/Source/Core/VideoBackends/D3D/D3DVertexManager.cpp @@ -225,8 +225,7 @@ void VertexManager::CommitBuffer(u32 num_vertices, u32 vertex_stride, u32 num_in u32 totalBufferSize = vertexBufferSize + indexBufferSize; u32 cursor = m_buffer_cursor; - u32 padding = vertex_stride > 0 ? (m_buffer_cursor % vertex_stride) : 0; - if (padding) + if (u32 padding = vertex_stride > 0 ? (m_buffer_cursor % vertex_stride) : 0) { cursor += vertex_stride - padding; } diff --git a/Source/Core/VideoBackends/OGL/OGLStreamBuffer.h b/Source/Core/VideoBackends/OGL/OGLStreamBuffer.h index 3b8b7daf89..efc8ad767c 100644 --- a/Source/Core/VideoBackends/OGL/OGLStreamBuffer.h +++ b/Source/Core/VideoBackends/OGL/OGLStreamBuffer.h @@ -35,8 +35,7 @@ public: std::pair Map(u32 size, u32 stride) { - u32 padding = m_iterator % stride; - if (padding) + if (u32 padding = m_iterator % stride) { m_iterator += stride - padding; } diff --git a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp index 91794696b9..49d71333d9 100644 --- a/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp +++ b/Source/Core/VideoBackends/OGL/ProgramShaderCache.cpp @@ -57,8 +57,7 @@ static thread_local bool s_is_shared_context = false; static std::string GetGLSLVersionString() { - GlslVersion v = g_ogl_config.eSupportedGLSLVersion; - switch (v) + switch (g_ogl_config.eSupportedGLSLVersion) { case GlslEs300: return "#version 300 es"; diff --git a/Source/Core/VideoBackends/Vulkan/VKGfx.cpp b/Source/Core/VideoBackends/Vulkan/VKGfx.cpp index ea4d972864..99f7a9a7fd 100644 --- a/Source/Core/VideoBackends/Vulkan/VKGfx.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKGfx.cpp @@ -471,8 +471,7 @@ void VKGfx::SetTexture(u32 index, const AbstractTexture* texture) { // Texture should always be in SHADER_READ_ONLY layout prior to use. // This is so we don't need to transition during render passes. - const VKTexture* tex = static_cast(texture); - if (tex) + if (const VKTexture* tex = static_cast(texture)) { if (tex->GetLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { @@ -514,8 +513,7 @@ void VKGfx::SetSamplerState(u32 index, const SamplerState& state) void VKGfx::SetComputeImageTexture(u32 index, AbstractTexture* texture, bool read, bool write) { - VKTexture* vk_texture = static_cast(texture); - if (vk_texture) + if (VKTexture* vk_texture = static_cast(texture)) { StateTracker::GetInstance()->EndRenderPass(); StateTracker::GetInstance()->SetImageTexture(index, vk_texture->GetView()); diff --git a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp index 6756305d1e..7f44c4529d 100644 --- a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp @@ -381,7 +381,6 @@ void VKTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8* const u32 num_rows = Common::AlignUp(height, block_size) / block_size; const u32 source_pitch = CalculateStrideForFormat(m_config.format, row_length); const u32 upload_size = source_pitch * num_rows; - std::unique_ptr temp_buffer; VkBuffer upload_buffer; VkDeviceSize upload_buffer_offset; @@ -409,8 +408,8 @@ void VKTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8* else { // Create a temporary staging buffer that is destroyed after the image is copied. - temp_buffer = StagingBuffer::Create(STAGING_BUFFER_TYPE_UPLOAD, upload_size, - VK_BUFFER_USAGE_TRANSFER_SRC_BIT); + std::unique_ptr temp_buffer = StagingBuffer::Create(STAGING_BUFFER_TYPE_UPLOAD, + upload_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); if (!temp_buffer || !temp_buffer->Map()) { PanicAlertFmt("Failed to allocate staging texture for large texture upload."); diff --git a/Source/Core/VideoCommon/Assets/CustomAssetLoader.h b/Source/Core/VideoCommon/Assets/CustomAssetLoader.h index 90d4f81a0e..fdde1d5060 100644 --- a/Source/Core/VideoCommon/Assets/CustomAssetLoader.h +++ b/Source/Core/VideoCommon/Assets/CustomAssetLoader.h @@ -63,8 +63,7 @@ private: auto [it, inserted] = asset_map.try_emplace(asset_id); if (!inserted) { - auto shared = it->second.lock(); - if (shared) + if (auto shared = it->second.lock()) return shared; } std::shared_ptr ptr(new AssetType(std::move(library), asset_id), [&](AssetType* a) { diff --git a/Source/Core/VideoCommon/FrameDumpFFMpeg.cpp b/Source/Core/VideoCommon/FrameDumpFFMpeg.cpp index 760ae6f7e0..29a6af161c 100644 --- a/Source/Core/VideoCommon/FrameDumpFFMpeg.cpp +++ b/Source/Core/VideoCommon/FrameDumpFFMpeg.cpp @@ -223,8 +223,8 @@ bool FFMpegFrameDump::CreateVideoFile() if (!codec_name.empty()) { - const AVCodecDescriptor* const codec_desc = avcodec_descriptor_get_by_name(codec_name.c_str()); - if (codec_desc) + if (const AVCodecDescriptor* const codec_desc = + avcodec_descriptor_get_by_name(codec_name.c_str())) codec_id = codec_desc->id; else WARN_LOG_FMT(FRAMEDUMP, "Invalid codec {}", codec_name); diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp index 473cc06690..79d57a12a1 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp @@ -189,9 +189,9 @@ void CustomPipeline::UpdatePixelData( return; } - std::size_t max_material_data_size = 0; if (m_pixel_material.m_asset->GetLastLoadedTime() > m_pixel_material.m_cached_write_time) { + std::size_t max_material_data_size = 0; m_last_generated_material_code = ShaderCode{}; m_pixel_material.m_cached_write_time = m_pixel_material.m_asset->GetLastLoadedTime(); std::size_t texture_count = 0; diff --git a/Source/Core/VideoCommon/PostProcessing.cpp b/Source/Core/VideoCommon/PostProcessing.cpp index 7b66269ec7..dd8ae71e45 100644 --- a/Source/Core/VideoCommon/PostProcessing.cpp +++ b/Source/Core/VideoCommon/PostProcessing.cpp @@ -608,7 +608,6 @@ void PostProcessing::BlitFromTexture(const MathUtil::Rectangle& dst, std::string PostProcessing::GetUniformBufferHeader(bool user_post_process) const { std::ostringstream ss; - u32 unused_counter = 1; ss << "UBO_BINDING(std140, 1) uniform PSBlock {\n"; // Builtin uniforms: @@ -640,6 +639,7 @@ std::string PostProcessing::GetUniformBufferHeader(bool user_post_process) const if (user_post_process) { + u32 unused_counter = 1; ss << "\n"; // Custom options/uniforms for (const auto& it : m_config.GetOptions()) diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index 587ee3cc7f..de63c1204e 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -122,8 +122,7 @@ const AbstractPipeline* ShaderCache::GetPipelineForUid(const GXPipelineUid& uid) const bool exists_in_cache = it != m_gx_pipeline_cache.end(); std::unique_ptr pipeline; - std::optional pipeline_config = GetGXPipelineConfig(uid); - if (pipeline_config) + if (std::optional pipeline_config = GetGXPipelineConfig(uid)) pipeline = g_gfx->CreatePipeline(*pipeline_config); if (g_ActiveConfig.bShaderCache && !exists_in_cache) AppendGXPipelineUID(uid); @@ -154,8 +153,7 @@ const AbstractPipeline* ShaderCache::GetUberPipelineForUid(const GXUberPipelineU return it->second.first.get(); std::unique_ptr pipeline; - std::optional pipeline_config = GetGXPipelineConfig(uid); - if (pipeline_config) + if (std::optional pipeline_config = GetGXPipelineConfig(uid)) pipeline = g_gfx->CreatePipeline(*pipeline_config); return InsertGXUberPipeline(uid, std::move(pipeline)); } @@ -234,8 +232,7 @@ void ShaderCache::LoadShaderCache(T& cache, APIType api_type, const char* type, CacheReader(T& cache_) : cache(cache_) {} void Read(const K& key, const u8* value, u32 value_size) override { - auto shader = g_gfx->CreateShaderFromBinary(stage, value, value_size); - if (shader) + if (auto shader = g_gfx->CreateShaderFromBinary(stage, value, value_size)) { auto& entry = cache.shader_map[key]; entry.shader = std::move(shader); diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index b99533eb02..71f03884fb 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -760,8 +760,7 @@ void TextureCacheBase::DoLoadState(PointerWrap& p) p.Do(hash); p.Do(id); - auto& entry = GetEntry(id); - if (entry) + if (auto& entry = GetEntry(id)) entry->textures_by_hash_iter = m_textures_by_hash.emplace(hash, entry); } @@ -778,8 +777,7 @@ void TextureCacheBase::DoLoadState(PointerWrap& p) p.Do(index); p.Do(id); - auto& entry = GetEntry(id); - if (entry) + if (auto& entry = GetEntry(id)) m_bound_textures[index] = entry; } } @@ -869,15 +867,13 @@ RcTcacheEntry TextureCacheBase::DoPartialTextureUpdates(RcTcacheEntry& entry_to_ continue; } - auto reinterpreted_entry = ReinterpretEntry(entry, entry_to_update->format.texfmt); - if (reinterpreted_entry) + if (auto reinterpreted_entry = ReinterpretEntry(entry, entry_to_update->format.texfmt)) entry = reinterpreted_entry; } if (isPaletteTexture) { - auto decoded_entry = ApplyPaletteToEntry(entry, palette, tlutfmt); - if (decoded_entry) + if (auto decoded_entry = ApplyPaletteToEntry(entry, palette, tlutfmt)) { // Link the efb copy with the partially updated texture, so we won't apply this partial // update again @@ -1599,11 +1595,9 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp u32 width = texture_info.GetRawWidth(); if (hires_texture) { - auto asset = hires_texture->GetAsset(); - if (asset) + if (auto asset = hires_texture->GetAsset()) { - auto data = asset->GetData(); - if (data) + if (auto data = asset->GetData()) { if (!data->m_texture.m_slices.empty()) { @@ -1628,8 +1622,7 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp data_for_assets.reserve(cached_game_assets.size()); for (auto& cached_asset : cached_game_assets) { - auto data = cached_asset.m_asset->GetData(); - if (data) + if (auto data = cached_asset.m_asset->GetData()) { if (cached_asset.m_asset->Validate(texture_info.GetRawWidth(), texture_info.GetRawHeight())) { diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index 02edb56d35..45f00d567f 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -582,8 +582,7 @@ void VertexManagerBase::Flush() { for (const u32 i : used_textures) { - const auto cache_entry = g_texture_cache->Load(TextureInfo::FromStage(i)); - if (cache_entry) + if (const auto cache_entry = g_texture_cache->Load(TextureInfo::FromStage(i))) { if (std::find(texture_names.begin(), texture_names.end(), cache_entry->texture_info_name) == texture_names.end()) @@ -903,8 +902,7 @@ void VertexManagerBase::UpdatePipelineObject() case ShaderCompilationMode::AsynchronousSkipRendering: { // Can we background compile shaders? If so, get the pipeline asynchronously. - auto res = g_shader_cache->GetPipelineForUidAsync(m_current_pipeline_config); - if (res) + if (auto res = g_shader_cache->GetPipelineForUidAsync(m_current_pipeline_config)) { // Specialized shaders are ready, prefer these. m_current_pipeline_object = *res; diff --git a/Source/Core/VideoCommon/XFStructs.cpp b/Source/Core/VideoCommon/XFStructs.cpp index e5ca9b81ea..54d211ae8c 100644 --- a/Source/Core/VideoCommon/XFStructs.cpp +++ b/Source/Core/VideoCommon/XFStructs.cpp @@ -502,8 +502,7 @@ std::string GetXFMemName(u32 address) else if (address >= XFMEM_LIGHTS && address < XFMEM_LIGHTS_END) { const u32 light = (address - XFMEM_LIGHTS) / 16; - const u32 offset = (address - XFMEM_LIGHTS) % 16; - switch (offset) + switch (const u32 offset = (address - XFMEM_LIGHTS) % 16) { default: return fmt::format("Light {} unused param {}", light, offset); diff --git a/Source/Core/WinUpdater/WinUI.cpp b/Source/Core/WinUpdater/WinUI.cpp index 696ac55b0a..4f25bd3a9f 100644 --- a/Source/Core/WinUpdater/WinUI.cpp +++ b/Source/Core/WinUpdater/WinUI.cpp @@ -292,8 +292,7 @@ void Sleep(int sleep) void WaitForPID(u32 pid) { - HANDLE parent_handle = OpenProcess(SYNCHRONIZE, FALSE, static_cast(pid)); - if (parent_handle) + if (HANDLE parent_handle = OpenProcess(SYNCHRONIZE, FALSE, static_cast(pid))) { WaitForSingleObject(parent_handle, INFINITE); CloseHandle(parent_handle); diff --git a/Source/UnitTests/Common/BitFieldTest.cpp b/Source/UnitTests/Common/BitFieldTest.cpp index bb0de4b4ab..5461ad1a16 100644 --- a/Source/UnitTests/Common/BitFieldTest.cpp +++ b/Source/UnitTests/Common/BitFieldTest.cpp @@ -84,10 +84,9 @@ TEST(BitField, Storage) TEST(BitField, Read) { - TestUnion object; - for (u64 val : table) { + TestUnion object; object.hex = val; // Make sure reading/casting does not behave completely idiotic