diff --git a/Utilities/StrUtil.h b/Utilities/StrUtil.h index 33e021f6ba..5df0cce332 100644 --- a/Utilities/StrUtil.h +++ b/Utilities/StrUtil.h @@ -25,12 +25,6 @@ inline void strcpy_trunc(char (&dst)[N], const char (&src)[N2]) std::memset(dst + count, 0, N - count); } -template -inline bool ends_with(const std::string& src, const char (&end)[N]) -{ - return src.size() >= N - 1 && src.compare(src.size() - (N - 1), N - 1, end, N - 1) == 0; -} - namespace fmt { std::string replace_first(const std::string& src, const std::string& from, const std::string& to); diff --git a/rpcs3/Crypto/unpkg.cpp b/rpcs3/Crypto/unpkg.cpp index 19d30fface..3dfdf570f0 100644 --- a/rpcs3/Crypto/unpkg.cpp +++ b/rpcs3/Crypto/unpkg.cpp @@ -113,7 +113,7 @@ bool pkg_install(const std::string& path, atomic_t& sync) if (header.pkg_size > filelist[0].size()) { // Check if multi-files pkg - if (path.size() < 7 || path.compare(path.size() - 7, 7, "_00.pkg", 7) != 0) + if (!path.ends_with("_00.pkg")) { pkg_log.error("PKG file size mismatch (pkg_size=0x%llx)", header.pkg_size); return false; diff --git a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp index 7de45d251a..666a4184a6 100644 --- a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp @@ -395,7 +395,7 @@ static s32 savedata_check_args(u32 operation, u32 version, vm::cptr dirNam if (cur == '\0' || cur == '|') { // Check prefix if not empty - if (posprefix) + if (posprefix) { switch (sysutil_check_name_string(buf, 1, CELL_SAVEDATA_DIRNAME_SIZE)) { @@ -592,7 +592,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v for (const auto& prefix : prefix_list) { - if (entry.name.substr(0, prefix.size()) == prefix) + if (entry.name.starts_with(prefix)) { // Count the amount of matches and the amount of listed directories listGet->dirNum++; // total number of directories diff --git a/rpcs3/Emu/Cell/Modules/cellSysCache.cpp b/rpcs3/Emu/Cell/Modules/cellSysCache.cpp index 780f413627..3cea80eeb2 100644 --- a/rpcs3/Emu/Cell/Modules/cellSysCache.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSysCache.cpp @@ -58,7 +58,7 @@ struct syscache_info for (auto&& entry : fs::dir(cache_root)) { - if (entry.is_directory && entry.name.size() >= prefix.size() && entry.name.compare(0, prefix.size(), prefix) == 0) + if (entry.is_directory && entry.name.starts_with(prefix)) { cache_id = std::move(entry.name); break; diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index d187be9ca3..52d46815ba 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -1404,7 +1404,7 @@ extern void ppu_initialize(const ppu_module& info) const std::string dev_flash = vfs::get("/dev_flash/"); - if (info.path.compare(0, dev_flash.size(), dev_flash) != 0 && !Emu.GetTitleID().empty() && Emu.GetCat() != "1P") + if (!info.path.starts_with(dev_flash) && !Emu.GetTitleID().empty() && Emu.GetCat() != "1P") { // Add prefix for anything except dev_flash files, standalone elfs or PS1 classics cache_path += Emu.GetTitleID(); diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index 27b443b49a..2e5e993bf6 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -70,7 +70,7 @@ lv2_fs_mount_point* lv2_fs_object::get_mp(std::string_view filename) if (mp_name == "dev_hdd1"sv) return &g_mp_sys_dev_hdd1; - if (mp_name.substr(0, 7) == "dev_usb"sv) + if (mp_name.starts_with("dev_usb"sv)) return &g_mp_sys_dev_usb; if (mp_name == "dev_bdvd"sv) return &g_mp_sys_dev_bdvd; @@ -658,7 +658,7 @@ error_code sys_fs_opendir(ppu_thread& ppu, vm::cptr path, vm::ptr fd) data.back().name = vfs::unescape(data.back().name); // Add additional entries for split file candidates (while ends with .66600) - while (data.back().name.size() >= 6 && data.back().name.compare(data.back().name.size() - 6, 6, ".66600", 6) == 0) + while (data.back().name.ends_with(".66600")) { data.emplace_back(data.back()).name.resize(data.back().name.size() - 6); } diff --git a/rpcs3/Emu/Cell/lv2/sys_prx.cpp b/rpcs3/Emu/Cell/lv2/sys_prx.cpp index c924ef0c2a..38466c1d34 100644 --- a/rpcs3/Emu/Cell/lv2/sys_prx.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_prx.cpp @@ -121,7 +121,7 @@ static error_code prx_load_module(const std::string& vpath, u64 flags, vm::ptr thread, u32 g { if (g_cfg.core.max_spurs_threads < 6 && group->max_num > 0u + g_cfg.core.max_spurs_threads) { - if (group->name.size() >= 20 && group->name.compare(group->name.size() - 20, 20, "CellSpursKernelGroup", 20) == 0) + if (group->name.starts_with("CellSpursKernelGroup")) { // Hack: don't run more SPURS threads than specified. group->max_run = g_cfg.core.max_spurs_threads; @@ -511,7 +511,7 @@ error_code sys_spu_thread_group_create(ppu_thread& ppu, vm::ptr id, u32 num mem_size = 0x40000 * num; } - if (num < min_threads || num > max_threads || + if (num < min_threads || num > max_threads || (needs_root && min_prio == 0x10) || (use_scheduler && (prio > 255 || prio < min_prio))) { return CELL_EINVAL; diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 0e84f7dd23..23d24e5d9c 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -159,7 +159,7 @@ void Emulator::Init() // Fixup savedata for (const auto& entry : fs::dir(save_path)) { - if (entry.is_directory && entry.name.compare(0, 8, ".backup_", 8) == 0) + if (entry.is_directory && entry.name.starts_with(".backup_")) { const std::string desired = entry.name.substr(8); const std::string pending = save_path + ".working_" + desired; @@ -904,7 +904,7 @@ void Emulator::Load(const std::string& title_id, bool add_only, bool force_globa } // Check .sprx filename - if (entry.name.size() >= 5 && fmt::to_upper(entry.name).compare(entry.name.size() - 5, 5, ".SPRX", 5) == 0) + if (fmt::to_upper(entry.name).ends_with(".SPRX")) { if (entry.name == "libfs_155.sprx") { @@ -1141,7 +1141,7 @@ void Emulator::Load(const std::string& title_id, bool add_only, bool force_globa for (auto&& entry : fs::dir{ins_dir}) { const std::string pkg = ins_dir + entry.name; - if (!entry.is_directory && ends_with(entry.name, ".PKG") && !InstallPkg(pkg)) + if (!entry.is_directory && entry.name.ends_with(".PKG") && !InstallPkg(pkg)) { sys_log.error("Failed to install %s", pkg); return; @@ -1155,7 +1155,7 @@ void Emulator::Load(const std::string& title_id, bool add_only, bool force_globa for (auto&& entry : fs::dir{pkg_dir}) { - if (entry.is_directory && entry.name.compare(0, 3, "PKG", 3) == 0) + if (entry.is_directory && entry.name.starts_with("PKG")) { const std::string pkg_file = pkg_dir + entry.name + "/INSTALL.PKG"; diff --git a/rpcs3/rpcs3qt/register_editor_dialog.cpp b/rpcs3/rpcs3qt/register_editor_dialog.cpp index e6e5c8c98b..ed6715abf6 100644 --- a/rpcs3/rpcs3qt/register_editor_dialog.cpp +++ b/rpcs3/rpcs3qt/register_editor_dialog.cpp @@ -101,9 +101,9 @@ void register_editor_dialog::updateRegister(const QString& text) if (first_brk != -1) { long reg_index = std::atol(reg.substr(first_brk + 1, reg.length() - first_brk - 2).c_str()); - if (reg.compare(0, 3, "GPR") == 0) str = fmt::format("%016llx", ppu.gpr[reg_index]); - if (reg.compare(0, 3, "FPR") == 0) str = fmt::format("%016llx", ppu.fpr[reg_index]); - if (reg.compare(0, 2, "VR") == 0) str = fmt::format("%016llx%016llx", ppu.vr[reg_index]._u64[1], ppu.vr[reg_index]._u64[0]); + if (reg.starts_with("GPR")) str = fmt::format("%016llx", ppu.gpr[reg_index]); + if (reg.starts_with("FPR")) str = fmt::format("%016llx", ppu.fpr[reg_index]); + if (reg.starts_with("VR")) str = fmt::format("%016llx%016llx", ppu.vr[reg_index]._u64[1], ppu.vr[reg_index]._u64[0]); } if (reg == "CR") str = fmt::format("%08x", ppu.cr.pack()); if (reg == "LR") str = fmt::format("%016llx", ppu.lr); @@ -118,7 +118,7 @@ void register_editor_dialog::updateRegister(const QString& text) { long reg_index; reg_index = atol(reg.substr(first_brk + 1, reg.length() - 2).c_str()); - if (reg.compare(0, 3, "GPR") == 0) str = fmt::format("%016llx%016llx", spu.gpr[reg_index]._u64[1], spu.gpr[reg_index]._u64[0]); + if (reg.starts_with("GPR")) str = fmt::format("%016llx%016llx", spu.gpr[reg_index]._u64[1], spu.gpr[reg_index]._u64[0]); } } @@ -143,14 +143,14 @@ void register_editor_dialog::OnOkay(const std::shared_ptr& _cpu) if (first_brk != -1) { const long reg_index = std::atol(reg.substr(first_brk + 1, reg.length() - first_brk - 2).c_str()); - if (reg.compare(0, 3, "GPR") == 0 || reg.compare(0, 3, "FPR") == 0) + if (reg.starts_with("GPR") || reg.starts_with("FPR")) { const ullong reg_value = std::stoull(value.substr(16, 31), 0, 16); - if (reg.compare(0, 3, "GPR") == 0) ppu.gpr[reg_index] = static_cast(reg_value); - if (reg.compare(0, 3, "FPR") == 0) ppu.fpr[reg_index] = std::bit_cast(reg_value); + if (reg.starts_with("GPR")) ppu.gpr[reg_index] = static_cast(reg_value); + if (reg.starts_with("FPR")) ppu.fpr[reg_index] = std::bit_cast(reg_value); return; } - if (reg.compare(0, 2, "VR") == 0) + if (reg.starts_with("VR")) { const ullong reg_value0 = std::stoull(value.substr(16, 31), 0, 16); const ullong reg_value1 = std::stoull(value.substr(0, 15), 0, 16); @@ -188,7 +188,7 @@ void register_editor_dialog::OnOkay(const std::shared_ptr& _cpu) if (first_brk != -1) { const long reg_index = std::atol(reg.substr(first_brk + 1, reg.length() - 2).c_str()); - if (reg.compare(0, 3, "GPR") == 0) + if (reg.starts_with("GPR")) { const ullong reg_value0 = std::stoull(value.substr(16, 31), 0, 16); const ullong reg_value1 = std::stoull(value.substr(0, 15), 0, 16); diff --git a/rpcs3/rpcs3qt/user_manager_dialog.cpp b/rpcs3/rpcs3qt/user_manager_dialog.cpp index 710d8187d6..3801a39f8d 100644 --- a/rpcs3/rpcs3qt/user_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/user_manager_dialog.cpp @@ -204,7 +204,7 @@ void user_manager_dialog::UpdateTable(bool mark_only) m_table->setItem(row, 1, username_item); // Compare current config value with the one in this user (only 8 digits in userId) - if (m_active_user.compare(0, 8, user.second.GetUserId()) == 0) + if (m_active_user.starts_with(user.second.GetUserId())) { user_id_item->setFont(bold_font); username_item->setFont(bold_font);