From c69691f19b87de868da2dc824cb00d4f0f76086d Mon Sep 17 00:00:00 2001 From: sampletext32 Date: Fri, 10 Apr 2020 21:48:32 +0300 Subject: [PATCH] Fix various explicitness, laziness, hard codes --- Utilities/File.cpp | 10 ++++------ Utilities/StrUtil.h | 2 +- Utilities/VirtualMemory.cpp | 2 +- rpcs3/Emu/CPU/CPUThread.cpp | 18 +++++++++++------- rpcs3/Emu/GDB.cpp | 6 +++--- rpcs3/rpcs3qt/cheat_manager.cpp | 12 ++++++------ 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 94d3f3f607..5a41fa9f06 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -1603,15 +1603,14 @@ bool fs::remove_all(const std::string& path, bool remove_root) continue; } - if (entry.is_directory == false) + if (!entry.is_directory) { if (!remove_file(path_append(path, entry.name))) { return false; } } - - if (entry.is_directory == true) + else { if (!remove_all(path_append(path, entry.name))) { @@ -1651,12 +1650,11 @@ u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment) continue; } - if (entry.is_directory == false) + if (!entry.is_directory) { result += ::align(entry.size, rounding_alignment); } - - if (entry.is_directory == true) + else { const u64 size = get_dir_size(path_append(path, entry.name), rounding_alignment); diff --git a/Utilities/StrUtil.h b/Utilities/StrUtil.h index c9a47a9f78..6f038194bf 100644 --- a/Utilities/StrUtil.h +++ b/Utilities/StrUtil.h @@ -81,7 +81,7 @@ namespace fmt template std::string merge(const T& source, const std::string& separator) { - if (!source.size()) + if (source.empty()) { return {}; } diff --git a/Utilities/VirtualMemory.cpp b/Utilities/VirtualMemory.cpp index 8abb4d3164..d03b26e307 100644 --- a/Utilities/VirtualMemory.cpp +++ b/Utilities/VirtualMemory.cpp @@ -154,7 +154,7 @@ namespace utils #else while ((m_file = ::shm_open("/rpcs3-mem1", O_RDWR | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) == -1) { - if (m_file == -1 && errno == EMFILE) + if (errno == EMFILE) { fmt::throw_exception("Too many open files. Raise the limit and try again."); } diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index e1212ac8fe..a43eea50d4 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -359,14 +359,18 @@ void cpu_thread::operator()() std::this_thread::sleep_for(1ms); } - if (id_type() == 1 && false) + switch (id_type()) { - g_fxo->get()->registered.push(id); - } - - if (id_type() == 2 && g_cfg.core.spu_prof) - { - g_fxo->get()->registered.push(id); + case 1: + //g_fxo->get()->registered.push(id); + break; + case 2: + if (g_cfg.core.spu_prof) + { + g_fxo->get()->registered.push(id); + } + break; + default: ; } // Register thread in g_cpu_array diff --git a/rpcs3/Emu/GDB.cpp b/rpcs3/Emu/GDB.cpp index f32f4c7122..e5fad4552f 100644 --- a/rpcs3/Emu/GDB.cpp +++ b/rpcs3/Emu/GDB.cpp @@ -543,7 +543,7 @@ bool gdb_thread::cmd_thread_info(gdb_cmd& cmd) std::string result; const auto on_select = [&](u32, cpu_thread& cpu) { - if (result.length()) { + if (!result.empty()) { result += ","; } result += u64_to_padded_hex(static_cast(cpu.id)); @@ -572,7 +572,7 @@ bool gdb_thread::cmd_read_register(gdb_cmd& cmd) auto ppu = static_cast*>(th.get()); u32 rid = hex_to_u32(cmd.data); std::string result = get_reg(ppu, rid); - if (!result.length()) { + if (result.empty()) { GDB.warning("Wrong register id %d.", rid); return send_cmd_ack("E01"); } @@ -622,7 +622,7 @@ bool gdb_thread::cmd_read_memory(gdb_cmd& cmd) //result += "xx"; } } - if (len && !result.length()) { + if (len && result.empty()) { //nothing read return send_cmd_ack("E01"); } diff --git a/rpcs3/rpcs3qt/cheat_manager.cpp b/rpcs3/rpcs3qt/cheat_manager.cpp index f5833c8163..bc1f8da2e5 100644 --- a/rpcs3/rpcs3qt/cheat_manager.cpp +++ b/rpcs3/rpcs3qt/cheat_manager.cpp @@ -245,12 +245,12 @@ bool cheat_engine::resolve_script(u32& final_offset, const u32 offset, const std while (index < red_script.size()) { - if (red_script[index] >= '0' && red_script[index] <= '9') + if (std::isdigit(static_cast(red_script[index]))) { std::string num_string; for (; index < red_script.size(); index++) { - if (red_script[index] < '0' || red_script[index] > '9') + if (!std::isdigit(static_cast(red_script[index]))) break; num_string += red_script[index]; @@ -348,15 +348,15 @@ std::vector cheat_engine::search(const T value, const std::vector& to_ else { // Looks through mapped memory - for (u32 page_ind = (0x10000 / 4096); page_ind < (0xF0000000 / 4096); page_ind++) + for (u32 page_start = 0x10000; page_start < 0xF0000000; page_start += 4096) { - if (vm::check_addr(page_ind * 4096)) + if (vm::check_addr(page_start)) { // Assumes the values are aligned for (u32 index = 0; index < 4096; index += sizeof(T)) { - if (*vm::get_super_ptr((page_ind * 4096) + index) == value_swapped) - results.push_back((page_ind * 4096) + index); + if (*vm::get_super_ptr(page_start + index) == value_swapped) + results.push_back(page_start + index); } } }