(gfx_thumbnail_path.c) Cache localized string

(menu_displaylist.c) Some optimizations:
* Make sure val_d is never bigger than 16, it should just
contain a number. 16 is more than plenty (and probably too big even)
* Hose val_d out of loops if its value never changes inside the loop
* Attempt to avoid calling msg_hash_to_str inside loops unnecessarily
This commit is contained in:
LibretroAdmin 2022-08-27 13:20:29 +02:00
parent 87de6bda46
commit 19c72a413f
4 changed files with 126 additions and 110 deletions

View File

@ -133,9 +133,10 @@ static const char *gfx_thumbnail_get_type(
unsigned type = 0; unsigned type = 0;
unsigned gfx_thumbnails = settings->uints.gfx_thumbnails; unsigned gfx_thumbnails = settings->uints.gfx_thumbnails;
unsigned menu_left_thumbnails = settings->uints.menu_left_thumbnails; unsigned menu_left_thumbnails = settings->uints.menu_left_thumbnails;
const char *val_off = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF);
if (!path_data) if (!path_data)
return msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF); return val_off;
switch (thumbnail_id) switch (thumbnail_id)
{ {
@ -152,7 +153,7 @@ static const char *gfx_thumbnail_get_type(
type = menu_left_thumbnails; type = menu_left_thumbnails;
break; break;
default: default:
return msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF); return val_off;
} }
switch (type) switch (type)
@ -168,7 +169,7 @@ static const char *gfx_thumbnail_get_type(
break; break;
} }
return msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF); return val_off;
} }
/* Returns true if specified thumbnail is enabled /* Returns true if specified thumbnail is enabled

View File

@ -4263,8 +4263,8 @@ static unsigned menu_displaylist_parse_cores(
for (i = 0; i < list_size; i++) for (i = 0; i < list_size; i++)
{ {
bool is_dir;
char label[64]; char label[64];
bool is_dir = false;
const char *path = NULL; const char *path = NULL;
enum msg_hash_enums enum_idx = MSG_UNKNOWN; enum msg_hash_enums enum_idx = MSG_UNKNOWN;
enum msg_file_type file_type = FILE_TYPE_NONE; enum msg_file_type file_type = FILE_TYPE_NONE;
@ -4275,6 +4275,7 @@ static unsigned menu_displaylist_parse_cores(
{ {
case RARCH_DIRECTORY: case RARCH_DIRECTORY:
file_type = FILE_TYPE_DIRECTORY; file_type = FILE_TYPE_DIRECTORY;
is_dir = true;
break; break;
case RARCH_COMPRESSED_ARCHIVE: case RARCH_COMPRESSED_ARCHIVE:
case RARCH_COMPRESSED_FILE_IN_ARCHIVE: case RARCH_COMPRESSED_FILE_IN_ARCHIVE:
@ -4286,7 +4287,6 @@ static unsigned menu_displaylist_parse_cores(
break; break;
} }
is_dir = (file_type == FILE_TYPE_DIRECTORY);
/* Need to preserve slash first time. */ /* Need to preserve slash first time. */
path = str_list->elems[i].data; path = str_list->elems[i].data;
@ -6063,7 +6063,11 @@ static unsigned menu_displaylist_populate_subsystem(
} }
else else
{ {
snprintf(s, sizeof(s),"Load %s", subsystem->desc); /* TODO/FIXME - localize */
size_t _len = strlcpy(s, "Load", sizeof(s));
s[_len ] = ' ';
s[_len+1] = '\0';
strlcat(s, subsystem->desc, sizeof(s));
/* If using RGUI with sublabels disabled, add the /* If using RGUI with sublabels disabled, add the
* appropriate text to the menu entry itself... */ * appropriate text to the menu entry itself... */
@ -14145,7 +14149,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
char* orig_val = setting->get_string_representation ? char* orig_val = setting->get_string_representation ?
strdup(setting->value.target.string) : setting->value.target.string; strdup(setting->value.target.string) : setting->value.target.string;
char val_s[256], val_d[32]; char val_s[256], val_d[16];
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx); snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
@ -14209,7 +14213,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
{ {
for (i = min; i <= max; i += step) for (i = min; i <= max; i += step)
{ {
char val_s[256], val_d[256]; char val_s[256], val_d[16];
int val = (int)i; int val = (int)i;
*setting->value.target.integer = val; *setting->value.target.integer = val;
@ -14288,7 +14292,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
{ {
for (i = min; i <= max; i += step) for (i = min; i <= max; i += step)
{ {
char val_s[256], val_d[256]; char val_s[256], val_d[16];
*setting->value.target.fraction = i; *setting->value.target.fraction = i;
@ -14315,12 +14319,14 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
} }
else else
{ {
char val_d[16];
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
for (i = min; i <= max; i += step) for (i = min; i <= max; i += step)
{ {
char val_s[16], val_d[16]; char val_s[16];
snprintf(val_s, sizeof(val_s), "%.2f", i); snprintf(val_s, sizeof(val_s), "%.2f", i);
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
if (menu_entries_append_enum(info->list, if (menu_entries_append_enum(info->list,
val_s, val_s,
@ -14364,7 +14370,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
{ {
for (i = min; i <= max; i += step) for (i = min; i <= max; i += step)
{ {
char val_s[256], val_d[256]; char val_s[256], val_d[16];
int val = (int)i; int val = (int)i;
*setting->value.target.unsigned_integer = val; *setting->value.target.unsigned_integer = val;
@ -14392,13 +14398,14 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
} }
else else
{ {
char val_d[16];
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
for (i = min; i <= max; i += step) for (i = min; i <= max; i += step)
{ {
char val_s[16], val_d[16]; char val_s[16];
int val = (int)i; int val = (int)i;
snprintf(val_s, sizeof(val_s), "%d", val); snprintf(val_s, sizeof(val_s), "%d", val);
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
if (menu_entries_append_enum(info->list, if (menu_entries_append_enum(info->list,
val_s, val_s,
@ -14448,7 +14455,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
for (i = 0; i < GFX_MAX_SHADERS+1; i++) for (i = 0; i < GFX_MAX_SHADERS+1; i++)
{ {
char val_d[256]; char val_d[16];
snprintf(val_d, sizeof(val_d), "%d", i); snprintf(val_d, sizeof(val_d), "%d", i);
if (menu_entries_append_enum(info->list, if (menu_entries_append_enum(info->list,
val_d, val_d,
@ -14497,14 +14504,14 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
if (tmp_str_list.size > 0) if (tmp_str_list.size > 0)
{ {
unsigned i; unsigned i;
char val_d[16];
unsigned size = (unsigned)tmp_str_list.size; unsigned size = (unsigned)tmp_str_list.size;
bool checked_found = false; bool checked_found = false;
unsigned checked = 0; unsigned checked = 0;
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
char val_d[256];
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
if (menu_entries_append_enum(info->list, if (menu_entries_append_enum(info->list,
tmp_str_list.elems[i].data, tmp_str_list.elems[i].data,
val_d, val_d,
@ -14549,7 +14556,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
{ {
for (i = min; i <= max; i += step) for (i = min; i <= max; i += step)
{ {
char val_s[256], val_d[256]; char val_s[256], val_d[16];
int val = (int)i; int val = (int)i;
*setting->value.target.integer = val; *setting->value.target.integer = val;
@ -14577,13 +14584,13 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
} }
else else
{ {
char val_d[16];
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
for (i = min; i <= max; i += step) for (i = min; i <= max; i += step)
{ {
char val_s[16], val_d[16]; char val_s[16];
int val = (int)i; int val = (int)i;
snprintf(val_s, sizeof(val_s), "%d", val); snprintf(val_s, sizeof(val_s), "%d", val);
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
if (menu_entries_append_enum(info->list, if (menu_entries_append_enum(info->list,
val_s, val_s,
@ -14628,7 +14635,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
{ {
for (i = min; i <= max; i += step) for (i = min; i <= max; i += step)
{ {
char val_s[256], val_d[256]; char val_s[256], val_d[16];
*setting->value.target.fraction = i; *setting->value.target.fraction = i;
@ -14655,12 +14662,12 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
} }
else else
{ {
char val_d[16];
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
for (i = min; i <= max; i += step) for (i = min; i <= max; i += step)
{ {
char val_s[16], val_d[16]; char val_s[16];
snprintf(val_s, sizeof(val_s), "%.2f", i); snprintf(val_s, sizeof(val_s), "%.2f", i);
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
if (menu_entries_append_enum(info->list, if (menu_entries_append_enum(info->list,
val_s, val_s,
@ -14704,7 +14711,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
{ {
for (i = min; i <= max; i += step) for (i = min; i <= max; i += step)
{ {
char val_s[256], val_d[256]; char val_s[256], val_d[16];
int val = (int)i; int val = (int)i;
*setting->value.target.unsigned_integer = val; *setting->value.target.unsigned_integer = val;
@ -14732,13 +14739,13 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
} }
else else
{ {
char val_d[16];
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
for (i = min; i <= max; i += step) for (i = min; i <= max; i += step)
{ {
char val_s[16], val_d[16]; char val_s[16];
int val = (int)i; int val = (int)i;
snprintf(val_s, sizeof(val_s), "%d", val); snprintf(val_s, sizeof(val_s), "%d", val);
snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx);
if (menu_entries_append_enum(info->list, if (menu_entries_append_enum(info->list,
val_s, val_s,

View File

@ -9017,66 +9017,68 @@ static bool setting_append_list_input_player_options(
#endif #endif
} }
for (j = 0; j < RARCH_BIND_LIST_END; j++)
{ {
char label[NAME_MAX_LENGTH]; const char *value_na =
char name[NAME_MAX_LENGTH]; msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE);
for (j = 0; j < RARCH_BIND_LIST_END; j++)
i = (j < RARCH_ANALOG_BIND_LIST_END)
? input_config_bind_order[j]
: j;
if (input_config_bind_map_get_meta(i))
continue;
name[0] = '\0';
if (!string_is_empty(buffer[user]))
{ {
size_t _len = strlcpy(label, buffer[user], sizeof(label)); char label[NAME_MAX_LENGTH];
label[_len ] = ' '; char name[NAME_MAX_LENGTH];
label[_len+1] = '\0';
}
else
label[0] = '\0';
if ( i = (j < RARCH_ANALOG_BIND_LIST_END)
settings->bools.input_descriptor_label_show ? input_config_bind_order[j]
&& (i < RARCH_FIRST_META_KEY) : j;
&& core_has_set_input_descriptor()
&& (i != RARCH_TURBO_ENABLE) if (input_config_bind_map_get_meta(i))
) continue;
{
if (system->input_desc_btn[user][i]) name[0] = '\0';
strlcat(label,
system->input_desc_btn[user][i], if (!string_is_empty(buffer[user]))
sizeof(label));
else
{ {
strlcat(label, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), size_t _len = strlcpy(label, buffer[user], sizeof(label));
sizeof(label)); label[_len ] = ' ';
label[_len+1] = '\0';
if (settings->bools.input_descriptor_hide_unbound)
continue;
} }
else
label[0] = '\0';
if (
settings->bools.input_descriptor_label_show
&& (i < RARCH_FIRST_META_KEY)
&& core_has_set_input_descriptor()
&& (i != RARCH_TURBO_ENABLE)
)
{
if (system->input_desc_btn[user][i])
strlcat(label,
system->input_desc_btn[user][i],
sizeof(label));
else
{
strlcat(label, value_na, sizeof(label));
if (settings->bools.input_descriptor_hide_unbound)
continue;
}
}
else
strlcat(label, input_config_bind_map_get_desc(i), sizeof(label));
snprintf(name, sizeof(name), "p%u_%s", user + 1, input_config_bind_map_get_base(i));
CONFIG_BIND_ALT(
list, list_info,
&input_config_binds[user][i],
user + 1,
user,
strdup(name),
strdup(label),
&defaults[i],
&group_info,
&subgroup_info,
parent_group);
(*list)[list_info->index - 1].bind_type = i + MENU_SETTINGS_BIND_BEGIN;
} }
else
strlcat(label, input_config_bind_map_get_desc(i), sizeof(label));
snprintf(name, sizeof(name), "p%u_%s", user + 1, input_config_bind_map_get_base(i));
CONFIG_BIND_ALT(
list, list_info,
&input_config_binds[user][i],
user + 1,
user,
strdup(name),
strdup(label),
&defaults[i],
&group_info,
&subgroup_info,
parent_group);
(*list)[list_info->index - 1].bind_type = i + MENU_SETTINGS_BIND_BEGIN;
} }
END_SUB_GROUP(list, list_info, parent_group); END_SUB_GROUP(list, list_info, parent_group);
@ -14017,28 +14019,32 @@ static bool setting_append_list(
&group_info, &group_info,
&subgroup_info, &subgroup_info,
parent_group); parent_group);
for (user = 0; user < MAX_USERS; user++)
{ {
static char binds_list[MAX_USERS][255]; const char *val_input_user_binds =
static char binds_label[MAX_USERS][255]; msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_USER_BINDS);
unsigned user_value = user + 1; for (user = 0; user < MAX_USERS; user++)
{
static char binds_list[MAX_USERS][255];
static char binds_label[MAX_USERS][255];
unsigned user_value = user + 1;
snprintf(binds_list[user], sizeof(binds_list[user]), "%d_input_binds_list", user_value); snprintf(binds_list[user], sizeof(binds_list[user]), "%d_input_binds_list", user_value);
snprintf(binds_label[user], sizeof(binds_label[user]), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_USER_BINDS), user_value); snprintf(binds_label[user], sizeof(binds_label[user]),
val_input_user_binds, user_value);
CONFIG_ACTION_ALT( CONFIG_ACTION_ALT(
list, list_info, list, list_info,
binds_list[user], binds_list[user],
binds_label[user], binds_label[user],
&group_info, &group_info,
&subgroup_info, &subgroup_info,
parent_group); parent_group);
(*list)[list_info->index - 1].ui_type = ST_UI_TYPE_BIND_BUTTON; (*list)[list_info->index - 1].ui_type = ST_UI_TYPE_BIND_BUTTON;
(*list)[list_info->index - 1].index = user_value; (*list)[list_info->index - 1].index = user_value;
(*list)[list_info->index - 1].index_offset = user; (*list)[list_info->index - 1].index_offset = user;
MENU_SETTINGS_LIST_CURRENT_ADD_ENUM_IDX_PTR(list, list_info, (enum msg_hash_enums)(MENU_ENUM_LABEL_INPUT_USER_1_BINDS + user)); MENU_SETTINGS_LIST_CURRENT_ADD_ENUM_IDX_PTR(list, list_info, (enum msg_hash_enums)(MENU_ENUM_LABEL_INPUT_USER_1_BINDS + user));
}
} }
END_SUB_GROUP(list, list_info, parent_group); END_SUB_GROUP(list, list_info, parent_group);
@ -20383,13 +20389,18 @@ static bool setting_append_list(
/* TODO/FIXME - add enum_idx */ /* TODO/FIXME - add enum_idx */
{ {
unsigned max_users = settings->uints.input_max_users; unsigned max_users = settings->uints.input_max_users;
const char *lbl_network_remote_enable =
msg_hash_to_str(MENU_ENUM_LABEL_NETWORK_REMOTE_ENABLE);
const char *val_network_remote_enable =
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETWORK_USER_REMOTE_ENABLE);
for (user = 0; user < max_users; user++) for (user = 0; user < max_users; user++)
{ {
char s1[64], s2[64]; char s1[64], s2[64];
snprintf(s1, sizeof(s1), "%s_user_p%d", msg_hash_to_str(MENU_ENUM_LABEL_NETWORK_REMOTE_ENABLE), user + 1); snprintf(s1, sizeof(s1), "%s_user_p%d",
snprintf(s2, sizeof(s2), msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETWORK_USER_REMOTE_ENABLE), user + 1); lbl_network_remote_enable, user + 1);
snprintf(s2, sizeof(s2), val_network_remote_enable, user + 1);
CONFIG_BOOL_ALT( CONFIG_BOOL_ALT(
list, list_info, list, list_info,

View File

@ -111,8 +111,7 @@ static bool find_content_by_crc(playlist_config_t *playlist_config,
{ {
playlist_config_set_path(playlist_config, playlists->elems[i].data); playlist_config_set_path(playlist_config, playlists->elems[i].data);
playlist = playlist_init(playlist_config); if (!(playlist = playlist_init(playlist_config)))
if (!playlist)
continue; continue;
for (j = 0; j < playlist_get_size(playlist); j++) for (j = 0; j < playlist_get_size(playlist); j++)
@ -178,14 +177,12 @@ static bool find_content_by_name(playlist_config_t *playlist_config,
/* We do it like this /* We do it like this
because we want names and paths to have the same order; because we want names and paths to have the same order;
we also want to read and parse a playlist only the first time. */ we also want to read and parse a playlist only the first time. */
playlist = playlist_ptrs[j]; if (!(playlist = playlist_ptrs[j]))
if (!playlist)
{ {
playlist_config_set_path(playlist_config, playlist_config_set_path(playlist_config,
playlists->elems[j].data); playlists->elems[j].data);
playlist = playlist_init(playlist_config); if (!(playlist = playlist_init(playlist_config)))
if (!playlist)
continue; continue;
playlist_ptrs[j] = playlist; playlist_ptrs[j] = playlist;
} }