From 820ffb9d2066582d301cb276d39266afce6fdd11 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 31 May 2019 06:43:20 +0200 Subject: [PATCH] Cleanups - cut down on the rest of unnecessary filestream_exists calls - only use filestream_exists immediately before filestream_delete or any other genuine filestream-related operations - when just checking if a path exists on the filesystem, just use path_is_valid - faster --- cheevos-new/badges.c | 3 +-- command.c | 13 ++++++------- frontend/drivers/platform_darwin.m | 8 +++++--- frontend/drivers/platform_gx.c | 2 +- frontend/drivers/platform_ps3.c | 4 ++-- managers/cheat_manager.c | 3 +-- menu/cbs/menu_cbs_ok.c | 23 ++++++++++++----------- menu/drivers/stripes.c | 22 +++++++++++----------- menu/menu_networking.c | 3 +-- tasks/task_save.c | 2 +- 10 files changed, 41 insertions(+), 42 deletions(-) diff --git a/cheevos-new/badges.c b/cheevos-new/badges.c index 4fadc5520a..87e3b4335d 100644 --- a/cheevos-new/badges.c +++ b/cheevos-new/badges.c @@ -1,6 +1,5 @@ #include #include -#include #ifdef HAVE_MENU #include "../menu/menu_driver.h" @@ -17,7 +16,7 @@ badges_ctx_t badges_ctx; bool badge_exists(const char* filepath) { - return filestream_exists(filepath); + return path_is_valid(filepath); } void set_badge_menu_texture(badges_ctx_t * badges, int i) diff --git a/command.c b/command.c index c89ea74e65..b1fdaebcce 100755 --- a/command.c +++ b/command.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #ifdef HAVE_CONFIG_H @@ -1136,16 +1135,16 @@ static void command_event_load_auto_state(void) settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); -#ifdef HAVE_NETWORKING - if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)) + if (!global || !settings->bools.savestate_auto_load) return; -#endif #ifdef HAVE_CHEEVOS if (rcheevos_hardcore_active) return; #endif - if (!global || !settings->bools.savestate_auto_load) +#ifdef HAVE_NETWORKING + if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)) return; +#endif savestate_name_auto = (char*)calloc(PATH_MAX_LENGTH, sizeof(*savestate_name_auto)); @@ -1154,7 +1153,7 @@ static void command_event_load_auto_state(void) file_path_str(FILE_PATH_AUTO_EXTENSION), savestate_name_auto_size); - if (!filestream_exists(savestate_name_auto)) + if (!path_is_valid(savestate_name_auto)) { free(savestate_name_auto); return; @@ -1518,7 +1517,7 @@ static bool command_event_save_core_config(void) sizeof(tmp)); strlcat(config_path, tmp, config_size); - if (!filestream_exists(config_path)) + if (!path_is_valid(config_path)) { found_path = true; break; diff --git a/frontend/drivers/platform_darwin.m b/frontend/drivers/platform_darwin.m index fc7478b3a8..03eb8354a0 100644 --- a/frontend/drivers/platform_darwin.m +++ b/frontend/drivers/platform_darwin.m @@ -447,14 +447,16 @@ static void frontend_darwin_get_environment_settings(int *argc, char *argv[], fill_pathname_join(assets_zip_path, bundle_path_buf, "assets.zip", sizeof(assets_zip_path)); - if (filestream_exists(assets_zip_path)) + if (path_is_valid(assets_zip_path)) { settings_t *settings = config_get_ptr(); RARCH_LOG("Assets ZIP found at [%s], setting up bundle assets extraction...\n", assets_zip_path); RARCH_LOG("Extraction dir will be: %s\n", home_dir_buf); - strlcpy(settings->arrays.bundle_assets_src, assets_zip_path, sizeof(settings->arrays.bundle_assets_src)); - strlcpy(settings->arrays.bundle_assets_dst, home_dir_buf, sizeof(settings->arrays.bundle_assets_dst)); + strlcpy(settings->arrays.bundle_assets_src, + assets_zip_path, sizeof(settings->arrays.bundle_assets_src)); + strlcpy(settings->arrays.bundle_assets_dst, + home_dir_buf, sizeof(settings->arrays.bundle_assets_dst)); settings->uints.bundle_assets_extract_version_current = 130; /* TODO/FIXME: Just hardcode this for now */ } #endif diff --git a/frontend/drivers/platform_gx.c b/frontend/drivers/platform_gx.c index 221210532d..b30ecee7c5 100644 --- a/frontend/drivers/platform_gx.c +++ b/frontend/drivers/platform_gx.c @@ -418,7 +418,7 @@ static void frontend_gx_process_args(int *argc, char *argv[]) { char path[PATH_MAX_LENGTH] = {0}; strlcpy(path, strrchr(argv[0], '/') + 1, sizeof(path)); - if (filestream_exists(path)) + if (path_is_valid(path)) path_set(RARCH_PATH_CORE, path); } #endif diff --git a/frontend/drivers/platform_ps3.c b/frontend/drivers/platform_ps3.c index 38c114b196..343024c51b 100644 --- a/frontend/drivers/platform_ps3.c +++ b/frontend/drivers/platform_ps3.c @@ -126,7 +126,7 @@ static void frontend_ps3_get_environment_settings(int *argc, char *argv[], #ifdef HAVE_MULTIMAN /* not launched from external launcher, set default path */ // second param is multiMAN SELF file - if ( filestream_exists(argv[2]) && *argc > 1 + if ( path_is_valid(argv[2]) && *argc > 1 && (string_is_equal(argv[2], EMULATOR_CONTENT_DIR))) { multiman_detected = true; @@ -606,7 +606,7 @@ static void frontend_ps3_process_args(int *argc, char *argv[]) { char path[PATH_MAX_LENGTH] = {0}; strlcpy(path, argv[0], sizeof(path)); - if (filestream_exists(path)) + if (path_is_valid(path)) path_set(RARCH_PATH_CORE, path); } #endif diff --git a/managers/cheat_manager.c b/managers/cheat_manager.c index 9d472ba988..d06a3932b1 100644 --- a/managers/cheat_manager.c +++ b/managers/cheat_manager.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -683,7 +682,7 @@ bool cheat_manager_get_game_specific_filename(char * cheat_filename, size_t max_ strlcat(cheat_filename, core_name, max_length); fill_pathname_slash(cheat_filename, max_length); - if (!filestream_exists(cheat_filename)) + if (!path_is_valid(cheat_filename)) path_mkdir(cheat_filename); strlcat(cheat_filename, game_name, max_length); diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 30cb64fd72..74172cbb81 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1387,10 +1387,9 @@ static int generic_action_ok(const char *path, strlcpy(settings->paths.path_menu_wallpaper, action_path, sizeof(settings->paths.path_menu_wallpaper)); - if (filestream_exists(action_path)) - task_push_image_load(action_path, - video_driver_supports_rgba(), - menu_display_handle_wallpaper_upload, NULL); + task_push_image_load(action_path, + video_driver_supports_rgba(), + menu_display_handle_wallpaper_upload, NULL); } break; case ACTION_OK_LOAD_CORE: @@ -1424,7 +1423,8 @@ static int generic_action_ok(const char *path, fill_pathname_join(destination_path, settings->paths.directory_libretro, path_basename(action_path), sizeof(destination_path)); - if(!file_copy(action_path, destination_path, message, sizeof(message))) + if (!file_copy( + action_path, destination_path, message, sizeof(message))) { runloop_msg_queue_push(msg_hash_to_str( MENU_ENUM_LABEL_VALUE_SIDELOAD_CORE_ERROR), 1, 100, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); @@ -2355,7 +2355,7 @@ static void menu_input_st_string_cb_save_preset(void *userdata, else if (!string_is_empty(label)) ret = menu_shader_manager_save_preset(str, false, false); - if(ret) + if (ret) runloop_msg_queue_push( msg_hash_to_str(MSG_SHADER_PRESET_SAVED_SUCCESSFULLY), 1, 100, true, @@ -2487,7 +2487,7 @@ static int generic_action_ok_shader_preset_save(const char *path, break; } - if(menu_shader_manager_save_preset(file, false, true)) + if (menu_shader_manager_save_preset(file, false, true)) runloop_msg_queue_push( msg_hash_to_str(MSG_SHADER_PRESET_SAVED_SUCCESSFULLY), 1, 100, true, @@ -2571,7 +2571,7 @@ static int generic_action_ok_remap_file_operation(const char *path, if (action_type < ACTION_OK_REMAP_FILE_REMOVE_CORE) { - if(input_remapping_save_file(file)) + if (input_remapping_save_file(file)) { if (action_type == ACTION_OK_REMAP_FILE_SAVE_CORE) rarch_ctl(RARCH_CTL_SET_REMAPS_CORE_ACTIVE, NULL); @@ -2593,7 +2593,7 @@ static int generic_action_ok_remap_file_operation(const char *path, } else { - if(input_remapping_remove_file(file)) + if (input_remapping_remove_file(file)) { if (action_type == ACTION_OK_REMAP_FILE_REMOVE_CORE && rarch_ctl(RARCH_CTL_IS_REMAPS_CORE_ACTIVE, NULL)) @@ -2764,9 +2764,10 @@ static int action_ok_set_switch_cpu_profile(const char *path, config_get_ptr()->uints.libnx_overclock = entry_idx; unsigned profile_clock = SWITCH_CPU_SPEEDS_VALUES[entry_idx]; - if(hosversionBefore(8, 0, 0)) { + if (hosversionBefore(8, 0, 0)) pcvSetClockRate(PcvModule_CpuBus, (u32)profile_clock); - } else { + else + { ClkrstSession session = {0}; clkrstOpenSession(&session, PcvModuleId_CpuBus, 3); clkrstSetClockRate(&session, profile_clock); diff --git a/menu/drivers/stripes.c b/menu/drivers/stripes.c index 88f2d50522..a238a67d2b 100644 --- a/menu/drivers/stripes.c +++ b/menu/drivers/stripes.c @@ -612,7 +612,7 @@ static void stripes_draw_icon( draw.y = height - y - shadow_offset; #if defined(VITA) || defined(WIIU) - if(scale_factor < 1) + if (scale_factor < 1) { draw.x = draw.x + (icon_size-draw.width)/2; draw.y = draw.y + (icon_size-draw.width)/2; @@ -626,7 +626,7 @@ static void stripes_draw_icon( draw.y = height - y; #if defined(VITA) || defined(WIIU) - if(scale_factor < 1) + if (scale_factor < 1) { draw.x = draw.x + (icon_size-draw.width)/2; draw.y = draw.y + (icon_size-draw.width)/2; @@ -1042,7 +1042,7 @@ static void stripes_update_savestate_thumbnail_path(void *data, unsigned i) strlcat(path, file_path_str(FILE_PATH_PNG_EXTENSION), path_size); - if (filestream_exists(path)) + if (path_is_valid(path)) { if (!string_is_empty(stripes->savestate_thumbnail_file_path)) free(stripes->savestate_thumbnail_file_path); @@ -1063,7 +1063,7 @@ static void stripes_update_thumbnail_image(void *data) if (!(string_is_empty(stripes->thumbnail_file_path))) { - if (filestream_exists(stripes->thumbnail_file_path)) + if (path_is_valid(stripes->thumbnail_file_path)) task_push_image_load(stripes->thumbnail_file_path, supports_rgba, menu_display_handle_thumbnail_upload, NULL); @@ -1076,7 +1076,7 @@ static void stripes_update_thumbnail_image(void *data) if (!(string_is_empty(stripes->left_thumbnail_file_path))) { - if (filestream_exists(stripes->left_thumbnail_file_path)) + if (path_is_valid(stripes->left_thumbnail_file_path)) task_push_image_load(stripes->left_thumbnail_file_path, supports_rgba, menu_display_handle_left_thumbnail_upload, NULL); @@ -1510,13 +1510,13 @@ static void stripes_list_switch_new(stripes_handle_t *stripes, file_path_str(FILE_PATH_PNG_EXTENSION), path_size); - if (!filestream_exists(path)) + if (!path_is_valid(path)) fill_pathname_application_special(path, path_size, APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_BG); - if(!string_is_equal(path, stripes->bg_file_path)) + if (!string_is_equal(path, stripes->bg_file_path)) { - if(filestream_exists(path)) + if (path_is_valid(path)) { task_push_image_load(path, video_driver_supports_rgba(), @@ -1944,7 +1944,7 @@ static void stripes_context_reset_horizontal_list( if (image_texture_load(&ti, texturepath)) { - if(ti.pixels) + if (ti.pixels) { video_driver_texture_unload(&node->icon); video_driver_texture_load(&ti, @@ -1961,7 +1961,7 @@ static void stripes_context_reset_horizontal_list( if (image_texture_load(&ti, content_texturepath)) { - if(ti.pixels) + if (ti.pixels) { video_driver_texture_unload(&node->content_icon); video_driver_texture_load(&ti, @@ -3679,7 +3679,7 @@ static void stripes_context_reset_background(const char *iconpath) PATH_MAX_LENGTH * sizeof(char)); } - if (filestream_exists(path)) + if (path_is_valid(path)) task_push_image_load(path, video_driver_supports_rgba(), menu_display_handle_wallpaper_upload, NULL); diff --git a/menu/menu_networking.c b/menu/menu_networking.c index b78d6d9b98..6c47bdf505 100644 --- a/menu/menu_networking.c +++ b/menu/menu_networking.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #ifdef HAVE_NETWORKING @@ -159,7 +158,7 @@ unsigned print_buf_lines(file_list_t *list, char *buf, sizeof(core_path)); if ( - filestream_exists(core_path) + path_is_valid(core_path) && core_info_get_display_name( core_path, display_name, sizeof(display_name))) file_list_set_alt_at_offset(list, j, display_name); diff --git a/tasks/task_save.c b/tasks/task_save.c index 3026a22149..e3d533ecae 100644 --- a/tasks/task_save.c +++ b/tasks/task_save.c @@ -1261,7 +1261,7 @@ bool content_save_state(const char *path, bool save_to_disk, bool autosave) if (save_to_disk) { - if (filestream_exists(path) && !autosave) + if (path_is_valid(path) && !autosave) { /* Before overwritting the savestate file, load it into a buffer to allow undo_save_state() to work */