From 3adde6a26fa199efbcdaad21fe30c61429d0647a Mon Sep 17 00:00:00 2001 From: korenkonder Date: Tue, 5 Mar 2024 00:27:53 +0300 Subject: [PATCH] std::string. Replaced += with `append` --- src/CRE/auth_3d.cpp | 2 +- src/CRE/data.cpp | 53 +++++++++++++-------------- src/CRE/file_handler.cpp | 4 +- src/KKdLib/io/path.cpp | 4 +- src/KKdLib/io/stream.cpp | 4 +- src/KKdLib/key_val.cpp | 10 ++--- src/MMPlusDec/MMPlusDec.cpp | 4 +- src/ReDIVA/data_test/auth_3d_test.cpp | 2 +- src/ReDIVA/x_pv_game.cpp | 2 +- 9 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/CRE/auth_3d.cpp b/src/CRE/auth_3d.cpp index 9db739c7..e60e1245 100644 --- a/src/CRE/auth_3d.cpp +++ b/src/CRE/auth_3d.cpp @@ -2971,7 +2971,7 @@ void auth_3d_data_get_obj_sets_from_category(std::string& name, std::vectorget_object_set_id(stgpv.c_str()); if (obj_set != -1) diff --git a/src/CRE/data.cpp b/src/CRE/data.cpp index c3eba2f8..fef336f4 100644 --- a/src/CRE/data.cpp +++ b/src/CRE/data.cpp @@ -294,7 +294,7 @@ bool data_struct::check_directory_exists(const char* dir) { for (data_struct_path& i : data_paths) for (data_struct_directory& j : i.data) { temp.assign(j.path); - temp += '\\'; + temp.push_back('\\'); temp.append(dir_temp); if (path_check_directory_exists(temp.c_str())) @@ -306,13 +306,13 @@ bool data_struct::check_directory_exists(const char* dir) { bool data_struct::check_file_exists(const char* path) { const char* t = strrchr(path, '/'); if (t) { - std::string dir = std::string(path, t - path + 1); + std::string dir(path, t - path + 1); return check_file_exists(dir.c_str(), t + 1); } t = strrchr(path, '\\'); if (t) { - std::string dir = std::string(path, t - path + 1); + std::string dir(path, t - path + 1); return check_file_exists(dir.c_str(), t + 1); } return false; @@ -330,7 +330,8 @@ bool data_struct::check_file_exists(const char* dir, const char* file) { t_len = file_len; uint32_t h = hash_murmurhash(file, t_len, 0, false, false); - std::string path = std::string(dir) + file; + std::string path(dir); + path.append(file); if (path_check_file_exists(path.c_str())) return true; } @@ -369,7 +370,7 @@ bool data_struct::check_file_exists(const char* dir, const char* file) { for (data_struct_path& i : data_paths) for (data_struct_directory& j : i.data) { temp.assign(j.path); - temp += '\\'; + temp.push_back('\\'); temp.append(dir_temp); temp.append(file, file_len); @@ -417,7 +418,7 @@ bool data_struct::check_file_exists(const char* dir, uint32_t hash) { for (data_struct_path& i : data_paths) for (data_struct_directory& j : i.data) { temp.assign(j.path); - temp += '\\'; + temp.push_back('\\'); temp.append(dir_temp); std::vector files = path_get_files(temp.c_str()); @@ -484,7 +485,7 @@ void data_struct::get_directory_files(const char* dir, std::vector files = path_get_files(temp.c_str()); @@ -545,7 +546,7 @@ bool data_struct::get_file(const char* dir, uint32_t hash, const char* ext, std: for (data_struct_path& i : data_paths) for (data_struct_directory& j : i.data) { temp.assign(j.path); - temp += '\\'; + temp.push_back('\\'); temp.append(dir_temp); std::vector files = path_get_files(temp.c_str()); @@ -578,13 +579,13 @@ bool data_struct::load_file(void* data, const char* path, bool (*load_func)(void* data, const char* path, const char* file, uint32_t hash)) { const char* t = strrchr(path, '/'); if (t) { - std::string dir = std::string(path, t - path + 1); + std::string dir(path, t - path + 1); return load_file(data, dir.c_str(), t + 1, load_func); } t = strrchr(path, '\\'); if (t) { - std::string dir = std::string(path, t - path + 1); + std::string dir(path, t - path + 1); return load_file(data, dir.c_str(), t + 1, load_func); } return false; @@ -642,7 +643,7 @@ bool data_struct::load_file(void* data, const char* dir, const char* file, for (data_struct_path& i : data_paths) for (data_struct_directory& j : i.data) { temp.assign(j.path); - temp += '\\'; + temp.push_back('\\'); temp.append(dir_temp); temp.append(file, file_len); @@ -704,7 +705,7 @@ bool data_struct::load_file(void* data, const char* dir, uint32_t hash, const ch for (data_struct_path& i : data_paths) for (data_struct_directory& j : i.data) { temp.assign(j.path); - temp += '\\'; + temp.push_back('\\'); temp.append(dir_temp); std::vector files = path_get_files(temp.c_str()); @@ -930,11 +931,10 @@ static void data_load_inner(stream& s) { ds->data_paths.reserve(count); for (size_t j = 0; j < count; j++) { - data_struct_path data_path; + ds->data_paths.push_back({}); + data_struct_path& data_path = ds->data_paths.back(); t -= t_len[count - j - 1] + 1; - data_path.path = std::string(t, t_len[count - j - 1]); - data_path.data = {}; - ds->data_paths.push_back(data_path); + data_path.path.assign(t, t_len[count - j - 1]); } free_def(t_len); @@ -945,7 +945,7 @@ static void data_load_inner(stream& s) { main_rom_path.assign(j.path); else if (data_path_length) { main_rom_path.assign(j.path); - main_rom_path += '\\'; + main_rom_path.push_back('\\'); main_rom_path.append(main_rom, main_rom_len); } else @@ -955,7 +955,7 @@ static void data_load_inner(stream& s) { add_data_rom_path.assign(j.path); else if (data_path_length) { add_data_rom_path.assign(j.path); - add_data_rom_path += '\\'; + add_data_rom_path.push_back('\\'); add_data_rom_path.append(add_data, add_data_len); } else @@ -976,27 +976,26 @@ static void data_load_inner(stream& s) { if (data_directories.size()) { j.data.reserve(data_directories.size() + 1); data_dir_path.assign(add_data_rom_path); - data_dir_path += '\\'; + data_dir_path.push_back('\\'); for (std::vector::reverse_iterator k = data_directories.rbegin(); k != data_directories.rend(); k++) { - data_struct_directory data_dir; + j.data.push_back({}); + data_struct_directory& data_dir = j.data.back(); data_dir.path.assign(data_dir_path); data_dir.path.append(*k); if (add_data_rom_len) { - data_dir.path += '\\'; + data_dir.path.push_back('\\'); data_dir.path.append(add_data_rom, add_data_rom_len); } data_dir.name.assign(*k); - j.data.push_back(data_dir); } } else j.data.reserve(1); - data_struct_directory data_dir; - data_dir.path = main_rom_path; - data_dir.name = {}; - j.data.push_back(data_dir); + j.data.push_back({}); + data_struct_directory& data_dir = j.data.back(); + data_dir.path.assign(main_rom_path); } ds->ready = true; } @@ -1027,7 +1026,7 @@ static void data_load_glitter_list(data_struct* ds, const char* path) { glitter_list_names.reserve(count); for (size_t i = 0; i < count; i++) { size_t len = utf8_length(lines[i]); - std::string name = std::string(lines[i], min_def(len, 0x7F)); + std::string name(lines[i], min_def(len, 0x7F)); glitter_list_names.push_back(name); } diff --git a/src/CRE/file_handler.cpp b/src/CRE/file_handler.cpp index 21834ba7..8772720e 100644 --- a/src/CRE/file_handler.cpp +++ b/src/CRE/file_handler.cpp @@ -381,13 +381,13 @@ size_t p_file_handler::get_size() { bool p_file_handler::read_file(void* data, const char* path) { const char* t = strrchr(path, '/'); if (t) { - std::string dir = std::string(path, t - path + 1); + std::string dir(path, t - path + 1); return read_file(data, dir.c_str(), 0, t + 1, false); } t = strrchr(path, '\\'); if (t) { - std::string dir = std::string(path, t - path + 1); + std::string dir(path, t - path + 1); return read_file(data, dir.c_str(), 0, t + 1, false); } return false; diff --git a/src/KKdLib/io/path.cpp b/src/KKdLib/io/path.cpp index 7c9dd396..7272d454 100644 --- a/src/KKdLib/io/path.cpp +++ b/src/KKdLib/io/path.cpp @@ -279,7 +279,7 @@ std::vector path_get_directories_recursive( std::vector directories; std::string path_temp; path_temp.assign(path); - path_temp += '\\'; + path_temp.push_back('\\'); for (std::string& i : temp_vec) { path_temp.append(i); std::vector temp = path_get_directories_recursive( @@ -301,7 +301,7 @@ std::vector path_get_directories_recursive( if (i.size()) { std::string sub_path_temp; sub_path_temp.assign(i); - sub_path_temp += '\\'; + sub_path_temp.push_back('\\'); for (std::string& j : temp) directories.push_back(sub_path_temp + j); } diff --git a/src/KKdLib/io/stream.cpp b/src/KKdLib/io/stream.cpp index 32c709fc..4d8e00df 100644 --- a/src/KKdLib/io/stream.cpp +++ b/src/KKdLib/io/stream.cpp @@ -62,13 +62,13 @@ void stream::write_uint8_t(uint8_t val) { } std::string stream::read_string(size_t length) { - std::string str = std::string(length, 0); + std::string str(length, 0); read(&str.front(), sizeof(char) * length); return str; } std::wstring stream::read_wstring(size_t length) { - std::wstring str = std::wstring(length, 0); + std::wstring str(length, 0); read(&str.front(), sizeof(wchar_t) * length); return str; } diff --git a/src/KKdLib/key_val.cpp b/src/KKdLib/key_val.cpp index 248bb5e5..da94d093 100644 --- a/src/KKdLib/key_val.cpp +++ b/src/KKdLib/key_val.cpp @@ -718,8 +718,8 @@ void key_val_out::open_scope(std::string& str) { temp_key.clear(); temp_key.reserve(curr_scope->size() + str.size() + 1); temp_key.assign(*curr_scope); - temp_key += '.'; - temp_key += str; + temp_key.push_back('.'); + temp_key.append(str); scope.push_back(temp_key); } else @@ -739,7 +739,7 @@ void key_val_out::open_scope(const char* str) { temp_key.clear(); temp_key.reserve(curr_scope->size() + str_len + 1); temp_key.assign(*curr_scope); - temp_key += '.'; + temp_key.push_back('.'); temp_key.append(str, str_len); scope.push_back(temp_key); } @@ -1140,7 +1140,7 @@ static int64_t key_val_get_key_index(key_val* kv, const char* key) { kv->temp_key.clear(); kv->temp_key.reserve(kv->curr_scope->key.size() + str_len + 1); kv->temp_key.assign(kv->curr_scope->key); - kv->temp_key += '.'; + kv->temp_key.push_back('.'); kv->temp_key.append(key, str_len); return key_val_get_key_index(kv, kv->temp_key.c_str(), kv->temp_key.size()); } @@ -1153,7 +1153,7 @@ static int64_t key_val_get_key_index(key_val* kv, std::string& key) { kv->temp_key.clear(); kv->temp_key.reserve(kv->curr_scope->key.size() + key.size() + 1); kv->temp_key.assign(kv->curr_scope->key); - kv->temp_key += '.'; + kv->temp_key.push_back('.'); kv->temp_key.append(key); return key_val_get_key_index(kv, kv->temp_key.c_str(), kv->temp_key.size()); } diff --git a/src/MMPlusDec/MMPlusDec.cpp b/src/MMPlusDec/MMPlusDec.cpp index 74e893fa..24f929a4 100644 --- a/src/MMPlusDec/MMPlusDec.cpp +++ b/src/MMPlusDec/MMPlusDec.cpp @@ -46,7 +46,7 @@ int32_t wmain(int32_t argc, wchar_t** argv) { } if (indir.back() != '\\') - indir += '\\'; + indir.push_back('\\'); bool encrypt = (argc == 3 && !str_utils_compare(argv[2], L"-e")) || (argc == 4 && !str_utils_compare(argv[3], L"-e")); @@ -56,7 +56,7 @@ int32_t wmain(int32_t argc, wchar_t** argv) { : (indir.substr(0, indir.size() - 1) + (encrypt ? L"_enc" : L"_dec")); if (outdir.back() != '\\') - outdir += '\\'; + outdir.push_back('\\'); if (!path_check_directory_exists(outdir.c_str()) && !CreateDirectoryW(outdir.c_str(), 0)) diff --git a/src/ReDIVA/data_test/auth_3d_test.cpp b/src/ReDIVA/data_test/auth_3d_test.cpp index 6e9f3610..5bb51d74 100644 --- a/src/ReDIVA/data_test/auth_3d_test.cpp +++ b/src/ReDIVA/data_test/auth_3d_test.cpp @@ -615,7 +615,7 @@ void Auth3dTestTask::SetStage() { size_t v24 = v20 - name; if (v24 != -1) { - std::string v30 = std::string(name + v16, v24 - v16); + std::string v30(name + v16, v24 - v16); int32_t stage_index = aft_stage_data->get_stage_index(v30.c_str()); if (this->stage_index != stage_index) load_stage_index = stage_index; diff --git a/src/ReDIVA/x_pv_game.cpp b/src/ReDIVA/x_pv_game.cpp index d1c4f396..7fdffe98 100644 --- a/src/ReDIVA/x_pv_game.cpp +++ b/src/ReDIVA/x_pv_game.cpp @@ -4375,7 +4375,7 @@ void x_pv_game_data::load(int32_t pv_id, FrameRateControl* frame_rate_control, c char buf[0x200]; size_t len = sprintf_s(buf, sizeof(buf), "exp_PV%03d", pv_id); - exp_file = std::string(buf, len); + exp_file.assign(buf, len); camera.load(pv_id, stage->stage_id, frame_rate_control);