Skip to content

Commit f2c598f

Browse files
committed
remove most of the remaining string_is_empty calls
also reduce calls to path_get
1 parent 675344c commit f2c598f

12 files changed

Lines changed: 93 additions & 68 deletions

command.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,10 +1443,12 @@ size_t command_event_save_auto_state(void)
14431443
runloop_state_t *runloop_st = runloop_state_get_ptr();
14441444
const char *name_savestate = runloop_st->name.savestate;
14451445
char savestate_name_auto[PATH_MAX_LENGTH];
1446+
const char *a = NULL;
14461447

14471448
if (!core_info_current_supports_savestate())
14481449
return 0;
1449-
if (string_is_empty(path_basename(path_get(RARCH_PATH_BASENAME))))
1450+
a = path_basename(path_get(RARCH_PATH_BASENAME));
1451+
if (!a || !*a)
14501452
return 0;
14511453
_len = strlcpy(savestate_name_auto, name_savestate,
14521454
sizeof(savestate_name_auto));

configuration.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4709,6 +4709,7 @@ static bool config_load_file(global_t *global,
47094709
*/
47104710
bool config_load_override(void *data)
47114711
{
4712+
const char *a = NULL;
47124713
char core_path[PATH_MAX_LENGTH];
47134714
char game_path[PATH_MAX_LENGTH];
47144715
char content_path[PATH_MAX_LENGTH];
@@ -4774,15 +4775,13 @@ bool config_load_override(void *data)
47744775
/* Create a new config file from core_path */
47754776
if (path_is_valid(core_path))
47764777
{
4778+
const char *a = path_get(RARCH_PATH_CONFIG_OVERRIDE);
47774779
RARCH_LOG("[Override] Core-specific overrides found at \"%s\".\n",
47784780
core_path);
4779-
4780-
if (should_append && !string_is_empty(path_get(RARCH_PATH_CONFIG_OVERRIDE)))
4781+
if (should_append && a && *a)
47814782
{
47824783
char tmp_path[PATH_MAX_LENGTH];
4783-
size_t _len = strlcpy(tmp_path,
4784-
path_get(RARCH_PATH_CONFIG_OVERRIDE),
4785-
sizeof(tmp_path) - 2);
4784+
size_t _len = strlcpy(tmp_path, a, sizeof(tmp_path) - 2);
47864785
tmp_path[ _len] = '|';
47874786
tmp_path[++_len] = '\0';
47884787
strlcpy(tmp_path + _len, core_path, sizeof(tmp_path) - _len);
@@ -4801,15 +4800,14 @@ bool config_load_override(void *data)
48014800
/* Create a new config file from content_path */
48024801
if (path_is_valid(content_path))
48034802
{
4803+
const char *a = path_get(RARCH_PATH_CONFIG_OVERRIDE);
48044804
RARCH_LOG("[Override] Content dir-specific overrides found at \"%s\".\n",
48054805
content_path);
48064806

4807-
if (should_append && !string_is_empty(path_get(RARCH_PATH_CONFIG_OVERRIDE)))
4807+
if (should_append && a && *a)
48084808
{
48094809
char tmp_path[PATH_MAX_LENGTH];
4810-
size_t _len = strlcpy(tmp_path,
4811-
path_get(RARCH_PATH_CONFIG_OVERRIDE),
4812-
sizeof(tmp_path) - 2);
4810+
size_t _len = strlcpy(tmp_path, a, sizeof(tmp_path) - 2);
48134811
tmp_path[ _len] = '|';
48144812
tmp_path[++_len] = '\0';
48154813
strlcpy(tmp_path + _len, content_path, sizeof(tmp_path) - _len);
@@ -4826,15 +4824,14 @@ bool config_load_override(void *data)
48264824
/* Create a new config file from game_path */
48274825
if (path_is_valid(game_path))
48284826
{
4827+
const char *a = path_get(RARCH_PATH_CONFIG_OVERRIDE);
48294828
RARCH_LOG("[Override] Game-specific overrides found at \"%s\".\n",
48304829
game_path);
48314830

4832-
if (should_append && !string_is_empty(path_get(RARCH_PATH_CONFIG_OVERRIDE)))
4831+
if (should_append && a && *a)
48334832
{
48344833
char tmp_path[PATH_MAX_LENGTH];
4835-
size_t _len = strlcpy(tmp_path,
4836-
path_get(RARCH_PATH_CONFIG_OVERRIDE),
4837-
sizeof(tmp_path) - 2);
4834+
size_t _len = strlcpy(tmp_path, a, sizeof(tmp_path) - 2);
48384835
tmp_path[ _len] = '|';
48394836
tmp_path[++_len] = '\0';
48404837
strlcpy(tmp_path + _len, game_path, sizeof(tmp_path) - _len);
@@ -4861,8 +4858,9 @@ bool config_load_override(void *data)
48614858
if (!config_load_file(global_get_ptr(), path_get(RARCH_PATH_CONFIG), settings))
48624859
return false;
48634860

4861+
a = path_get(RARCH_PATH_CONFIG_OVERRIDE);
48644862
if ( settings->bools.notification_show_config_override_load
4865-
&& !string_is_empty(path_get(RARCH_PATH_CONFIG_OVERRIDE)))
4863+
&& a && *a)
48664864
{
48674865
char msg[128];
48684866
size_t _len = strlcpy(msg, msg_hash_to_str(MSG_CONFIG_OVERRIDE_LOADED), sizeof(msg));
@@ -4874,7 +4872,8 @@ bool config_load_override(void *data)
48744872
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_STATE_PATH, NULL);
48754873
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_SAVE_PATH, NULL);
48764874

4877-
if (!string_is_empty(path_get(RARCH_PATH_CONFIG_OVERRIDE)))
4875+
a = path_get(RARCH_PATH_CONFIG_OVERRIDE);
4876+
if (a && *a)
48784877
runloop_state_get_ptr()->flags |= RUNLOOP_FLAG_OVERRIDES_ACTIVE;
48794878
else
48804879
runloop_state_get_ptr()->flags &= ~RUNLOOP_FLAG_OVERRIDES_ACTIVE;
@@ -4884,7 +4883,8 @@ bool config_load_override(void *data)
48844883

48854884
bool config_load_override_file(const char *config_path)
48864885
{
4887-
settings_t *settings = config_st;
4886+
const char *a = NULL;
4887+
settings_t *settings = config_st;
48884888

48894889
path_clear(RARCH_PATH_CONFIG_OVERRIDE);
48904890

@@ -4915,7 +4915,8 @@ bool config_load_override_file(const char *config_path)
49154915
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_STATE_PATH, NULL);
49164916
retroarch_override_setting_set(RARCH_OVERRIDE_SETTING_SAVE_PATH, NULL);
49174917

4918-
if (!string_is_empty(path_get(RARCH_PATH_CONFIG_OVERRIDE)))
4918+
a = path_get(RARCH_PATH_CONFIG_OVERRIDE);
4919+
if (a && *a)
49194920
runloop_state_get_ptr()->flags |= RUNLOOP_FLAG_OVERRIDES_ACTIVE;
49204921
else
49214922
runloop_state_get_ptr()->flags &= ~RUNLOOP_FLAG_OVERRIDES_ACTIVE;
@@ -5607,6 +5608,7 @@ bool config_save_autoconf_profile(const char *device_name, unsigned user)
56075608
unsigned i;
56085609
char buf[PATH_MAX_LENGTH];
56095610
char autoconf_file[PATH_MAX_LENGTH];
5611+
const char *a = NULL;
56105612
config_file_t *conf = NULL;
56115613
int32_t pid_user = 0;
56125614
int32_t vid_user = 0;
@@ -5702,9 +5704,11 @@ bool config_save_autoconf_profile(const char *device_name, unsigned user)
57025704
joypad_driver);
57035705
config_set_string(conf, "input_device",
57045706
input_config_get_device_name(settings->uints.input_joypad_index[user]));
5707+
a =
5708+
input_config_get_device_display_name(settings->uints.input_joypad_index[user]);
57055709
config_set_string(conf, "input_device_display_name",
5706-
!string_is_empty(input_config_get_device_display_name(settings->uints.input_joypad_index[user]))
5707-
? input_config_get_device_display_name(settings->uints.input_joypad_index[user])
5710+
(a && *a)
5711+
? a
57085712
: input_config_get_device_name(settings->uints.input_joypad_index[user]));
57095713

57105714
pid_user = input_config_get_device_pid(settings->uints.input_joypad_index[user]);

input/input_driver.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5984,6 +5984,7 @@ static const char *input_overlay_path(bool want_osk)
59845984
{
59855985
static char system_overlay_path[PATH_MAX_LENGTH] = {0};
59865986
char overlay_directory[PATH_MAX_LENGTH];
5987+
const char *a = NULL;
59875988
settings_t *settings = config_get_ptr();
59885989
playlist_t *playlist = playlist_get_cached();
59895990
core_info_t *core_info = NULL;
@@ -5998,7 +5999,8 @@ static const char *input_overlay_path(bool want_osk)
59985999
if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_OVERLAY_PRESET, NULL))
59996000
return settings->paths.path_overlay;
60006001
/* If there's no core, just return the default */
6001-
if (string_is_empty(path_get(RARCH_PATH_CORE)))
6002+
a = path_get(RARCH_PATH_CORE);
6003+
if (!a || !*a)
60026004
return settings->paths.path_overlay;
60036005
/* Let's go hunting */
60046006
fill_pathname_expand_special(overlay_directory,

menu/cbs/menu_cbs_ok.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -664,11 +664,12 @@ static const char *menu_driver_get_last_start_directory(void)
664664
settings_t *settings = config_get_ptr();
665665
bool use_last = settings->bools.use_last_start_directory;
666666
const char *default_directory = settings->paths.directory_menu_content;
667+
const char *a = path_get(RARCH_PATH_CONTENT);
667668

668669
/* Also treat content launched from CLI as last start content */
669670
if (menu && use_last && !*menu->last_start_content.file_name
670-
&& !string_is_empty(path_get(RARCH_PATH_CONTENT)))
671-
menu_driver_set_last_start_content(menu_st, path_get(RARCH_PATH_CONTENT));
671+
&& a && *a)
672+
menu_driver_set_last_start_content(menu_st, a);
672673

673674
/* Return default directory if there is no
674675
* last directory or it's invalid */
@@ -1390,9 +1391,9 @@ int generic_action_ok_displaylist_push(
13901391
break;
13911392
case ACTION_OK_DL_DISK_IMAGE_APPEND_LIST:
13921393
{
1394+
const char *a = path_get(RARCH_PATH_CONTENT);
13931395
filebrowser_clear_type();
1394-
fill_pathname_basedir(tmp,
1395-
path_get(RARCH_PATH_CONTENT), sizeof(tmp));
1396+
fill_pathname_basedir(tmp, a, sizeof(tmp));
13961397

13971398
info.type = type;
13981399
info.directory_ptr = idx;
@@ -1403,7 +1404,7 @@ int generic_action_ok_displaylist_push(
14031404
/* Focus on current content entry */
14041405
{
14051406
char path_content[PATH_MAX_LENGTH];
1406-
strlcpy(path_content, path_get(RARCH_PATH_CONTENT), sizeof(path_content));
1407+
strlcpy(path_content, a, sizeof(path_content));
14071408
/* Remove archive browsed file from the path */
14081409
{
14091410
char *delim = path_content;
@@ -5961,13 +5962,13 @@ static int action_ok_add_to_favorites(const char *path,
59615962
/* > core_path + core_name */
59625963
if (sysinfo)
59635964
{
5964-
if (!string_is_empty(path_get(RARCH_PATH_CORE)))
5965+
const char *a = path_get(RARCH_PATH_CORE);
5966+
if (a && *a)
59655967
{
59665968
core_info_t *core_info = NULL;
59675969

59685970
/* >> core_path */
5969-
strlcpy(core_path, path_get(RARCH_PATH_CORE),
5970-
sizeof(core_path));
5971+
strlcpy(core_path, a, sizeof(core_path));
59715972
/* >> core_name
59725973
* (always use display name, if available) */
59735974
if (core_info_find(core_path, &core_info))
@@ -6083,13 +6084,12 @@ static int action_ok_add_entry_to_playlist_quickmenu(const char *path,
60836084
/* > core_path + core_name */
60846085
if (sysinfo)
60856086
{
6086-
if (!string_is_empty(path_get(RARCH_PATH_CORE)))
6087+
const char *a = path_get(RARCH_PATH_CORE);
6088+
if (a && *a)
60876089
{
60886090
core_info_t *core_info = NULL;
6089-
60906091
/* >> core_path */
6091-
strlcpy(core_path, path_get(RARCH_PATH_CORE),
6092-
sizeof(core_path));
6092+
strlcpy(core_path, a, sizeof(core_path));
60936093
/* >> core_name
60946094
* (always use display name, if available) */
60956095
if (core_info_find(core_path, &core_info))

menu/menu_displaylist.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,14 +1523,14 @@ static unsigned menu_displaylist_parse_core_option_override_list(file_list_t *li
15231523
&& (runloop_st->core_options);
15241524
bool game_options_active = (flags & RUNLOOP_FLAG_GAME_OPTIONS_ACTIVE) ? true : false;
15251525
bool folder_options_active = (flags & RUNLOOP_FLAG_FOLDER_OPTIONS_ACTIVE) ? true : false;
1526+
const char *a = path_get(RARCH_PATH_CONTENT);
15261527

15271528
/* Sanity check - cannot handle core option
15281529
* overrides if:
15291530
* - Core is 'dummy'
15301531
* - Core has no options
15311532
* - No content has been loaded */
1532-
if ( !core_has_options
1533-
|| string_is_empty(path_get(RARCH_PATH_CONTENT)))
1533+
if (!core_has_options || (!a || !*a))
15341534
goto end;
15351535

15361536
/* Show currently active core options file */
@@ -1611,7 +1611,8 @@ static unsigned menu_displaylist_parse_remap_file_manager_list(file_list_t *list
16111611
{
16121612
unsigned count = 0;
16131613
uint32_t flags = runloop_get_flags();
1614-
bool has_content = !string_is_empty(path_get(RARCH_PATH_CONTENT));
1614+
const char *a = path_get(RARCH_PATH_CONTENT);
1615+
bool has_content = a && *a;
16151616
bool core_remap_active = (flags & RUNLOOP_FLAG_REMAPS_CORE_ACTIVE) ? true : false;
16161617
bool content_dir_remap_active = (flags & RUNLOOP_FLAG_REMAPS_CONTENT_DIR_ACTIVE) ? true : false;
16171618
bool game_remap_active = (flags & RUNLOOP_FLAG_REMAPS_GAME_ACTIVE) ? true : false;
@@ -7069,7 +7070,8 @@ unsigned menu_displaylist_build_list(
70697070

70707071
const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME);
70717072
const char *core_name = sys_info ? sys_info->info.library_name : NULL;
7072-
bool has_content = !string_is_empty(path_get(RARCH_PATH_CONTENT));
7073+
const char *a = path_get(RARCH_PATH_CONTENT);
7074+
bool has_content = (a && *a);
70737075
bool core_override_remove = false;
70747076
bool content_dir_override_remove = false;
70757077
bool game_override_remove = false;
@@ -7475,7 +7477,8 @@ unsigned menu_displaylist_build_list(
74757477
case DISPLAYLIST_SHADER_PRESET_MANAGER:
74767478
{
74777479
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
7478-
bool has_content = !string_is_empty(path_get(RARCH_PATH_CONTENT));
7480+
const char *a = path_get(RARCH_PATH_CONTENT);
7481+
bool has_content = (a && *a);
74797482
const char *dir_video_shader = settings->paths.directory_video_shader;
74807483
const char *dir_menu_config = settings->paths.directory_menu_config;
74817484

menu/menu_driver.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8039,14 +8039,16 @@ int generic_menu_entry_action(
80398039
}
80408040
else if (menu_st->flags & MENU_ST_FLAG_PENDING_RELOAD_CORE)
80418041
{
8042+
#ifdef HAVE_DYNAMIC
8043+
const char *a = path_get(RARCH_PATH_CORE_LAST);
8044+
#endif
80428045
menu_st->flags &= ~MENU_ST_FLAG_PENDING_RELOAD_CORE;
80438046

80448047
#ifdef HAVE_DYNAMIC
8045-
if (!string_is_empty(path_get(RARCH_PATH_CORE_LAST)))
8048+
if (a && *a)
80468049
{
80478050
content_ctx_info_t content_info = {0};
8048-
if (task_push_load_new_core(
8049-
path_get(RARCH_PATH_CORE_LAST),
8051+
if (task_push_load_new_core(a,
80508052
NULL,
80518053
&content_info,
80528054
CORE_TYPE_PLAIN,

retroarch.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,6 +2627,7 @@ bool path_set(enum rarch_path_type type, const char *path)
26272627

26282628
bool path_is_empty(enum rarch_path_type type)
26292629
{
2630+
const char *a = NULL;
26302631
struct rarch_state *p_rarch = &rarch_st;
26312632

26322633
switch (type)
@@ -2668,11 +2669,13 @@ bool path_is_empty(enum rarch_path_type type)
26682669
return true;
26692670
break;
26702671
case RARCH_PATH_BASENAME:
2671-
if (string_is_empty(runloop_state_get_ptr()->runtime_content_path_basename))
2672+
a = runloop_state_get_ptr()->runtime_content_path_basename;
2673+
if (!a || !*a)
26722674
return true;
26732675
break;
26742676
case RARCH_PATH_SUBSYSTEM:
2675-
if (string_is_empty(runloop_state_get_ptr()->subsystem_path))
2677+
a = runloop_state_get_ptr()->subsystem_path;
2678+
if (!a || !*a)
26762679
return true;
26772680
break;
26782681
case RARCH_PATH_NONE:

tasks/task_autodetect.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,12 @@ static void reallocate_port_if_needed(
518518
if (device_has_reserved_slot)
519519
{
520520
unsigned prev_assigned_port = settings->uints.input_joypad_index[player];
521+
const char *a = input_config_get_device_name(prev_assigned_port);
521522
if ( detected_port != prev_assigned_port
522-
&& !string_is_empty(input_config_get_device_name(prev_assigned_port))
523+
&& (a && *a)
523524
&& (( settings_value_vendor_id == input_config_get_device_vid(prev_assigned_port)
524525
&& settings_value_product_id == input_config_get_device_pid(prev_assigned_port))
525-
|| strcmp(input_config_get_device_name(prev_assigned_port), settings_value_device_name) == 0))
526+
|| strcmp(a, settings_value_device_name) == 0))
526527
{
527528
RARCH_DBG("[Autoconf] Same type of device already took this slot, continuing search...\n");
528529
device_has_reserved_slot = false;

tasks/task_cloudsync.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
#define CS_FILE_HASH(item_file) ((char*)((item_file) ? ((item_file)->userdata) : (NULL)))
4040
#define CS_FILE_KEY(item_file) ((item_file) ? ((item_file)->alt) : (NULL))
41-
#define CS_FILE_DELETED(item_file) (string_is_empty(CS_FILE_HASH(item_file)))
4241

4342
enum task_cloud_sync_phase
4443
{
@@ -859,7 +858,7 @@ static void task_cloud_sync_check_server_current(task_cloud_sync_state_t *sync_s
859858
task_cloud_sync_resolve_conflict(sync_state);
860859
else if (current_changed)
861860
task_cloud_sync_upload_current_file(sync_state);
862-
else if (!CS_FILE_DELETED(server_file))
861+
else if (!string_is_empty(CS_FILE_HASH(server_file)))
863862
task_cloud_sync_fetch_server_file(sync_state);
864863
else
865864
{
@@ -1019,7 +1018,7 @@ static void task_cloud_sync_diff_next(task_cloud_sync_state_t *sync_state)
10191018
if (server_current_key_cmp < 0)
10201019
{
10211020
/* the server has a file we don't have, we check the hash */
1022-
if (!CS_FILE_DELETED(server_file))
1021+
if (!string_is_empty(CS_FILE_HASH(server_file)))
10231022
task_cloud_sync_fetch_server_file(sync_state);
10241023
else
10251024
{
@@ -1065,9 +1064,9 @@ static void task_cloud_sync_diff_next(task_cloud_sync_state_t *sync_state)
10651064
else
10661065
{
10671066
/* the file has been deleted locally */
1068-
if (!CS_FILE_DELETED(server_file))
1067+
if (!string_is_empty(CS_FILE_HASH(server_file)))
10691068
{
1070-
if (CS_FILE_DELETED(local_file))
1069+
if (string_is_empty(CS_FILE_HASH(local_file)))
10711070
/* previously saw the delete, now it's resurrected */
10721071
task_cloud_sync_fetch_server_file(sync_state);
10731072
else if (string_is_equal(CS_FILE_HASH(server_file), CS_FILE_HASH(local_file)))

0 commit comments

Comments
 (0)