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
This commit is contained in:
twinaphex 2019-05-31 06:43:20 +02:00
parent 07d8daf048
commit 820ffb9d20
10 changed files with 41 additions and 42 deletions

View File

@ -1,6 +1,5 @@
#include <file/file_path.h>
#include <string/stdstring.h>
#include <streams/file_stream.h>
#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)

View File

@ -24,7 +24,6 @@
#include <file/file_path.h>
#include <lists/dir_list.h>
#include <string/stdstring.h>
#include <streams/file_stream.h>
#include <streams/stdin_stream.h>
#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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -24,7 +24,6 @@
#include <file/file_path.h>
#include <compat/strl.h>
#include <compat/posix_string.h>
#include <streams/file_stream.h>
#include <string/stdstring.h>
#include <retro_miscellaneous.h>
#include <features/features_cpu.h>
@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -23,7 +23,6 @@
#include <lists/string_list.h>
#include <file/file_path.h>
#include <compat/strl.h>
#include <streams/file_stream.h>
#include <string/stdstring.h>
#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);

View File

@ -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 */