Skip to content

Commit

Permalink
(core_info) Performance optimisations + code clean-ups/refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
jdgleaver committed Apr 26, 2021
1 parent 1d81841 commit f4511f6
Show file tree
Hide file tree
Showing 20 changed files with 580 additions and 779 deletions.
931 changes: 420 additions & 511 deletions core_info.c

Large diffs are not rendered by default.

48 changes: 13 additions & 35 deletions core_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,19 @@ typedef struct

/* Simple container/convenience struct for
* holding the 'id' of a core file
* > 'id' is the filename without extension or
* > 'str' is the filename without extension or
* platform-specific suffix
* > 'id' is used for core info searches - enables
* matching regardless of core file base path,
* and is platform-independent (e.g. an Android
* core file will be correctly identified on Linux)
* > 'len' is used to cache the length of 'str', for
* improved performance when performing string
* comparisons */
* > 'hash' is a hash key used for efficient core
* list searches */
typedef struct
{
char *str;
size_t len;
uint32_t hash;
} core_file_id_t;

typedef struct
{
char *path;
void *config_data;
char *display_name;
char *display_version;
char *core_name;
Expand All @@ -89,8 +83,8 @@ typedef struct
struct string_list *required_hw_api_list;
core_info_firmware_t *firmware;
core_file_id_t core_file_id; /* ptr alignment */
void *userdata;
size_t firmware_count;
bool has_info;
bool supports_no_game;
bool database_match_archive_member;
bool is_experimental;
Expand All @@ -112,6 +106,7 @@ typedef struct
core_info_t *list;
char *all_ext;
size_t count;
size_t info_count;
} core_info_list_t;

typedef struct core_info_ctx_firmware
Expand All @@ -123,12 +118,6 @@ typedef struct core_info_ctx_firmware
} directory;
} core_info_ctx_firmware_t;

typedef struct core_info_ctx_find
{
core_info_t *inf;
const char *path;
} core_info_ctx_find_t;

struct core_info_state
{
#ifdef HAVE_COMPRESSION
Expand All @@ -141,30 +130,21 @@ struct core_info_state

typedef struct core_info_state core_info_state_t;

size_t core_info_list_num_info_files(core_info_list_t *list);

/* Non-reentrant, does not allocate. Returns pointer to internal state. */
void core_info_list_get_supported_cores(core_info_list_t *list,
const char *path, const core_info_t **infos, size_t *num_infos);

bool core_info_list_get_display_name(core_info_list_t *list,
const char *path, char *s, size_t len);

bool core_info_get_display_name(const char *path, char *s, size_t len);
const char *core_path, char *s, size_t len);

/* Returns core_info parameters required for
* core updater tasks, read from specified file.
* Returned core_updater_info_t object must be
* freed using core_info_free_core_updater_info().
* Returns NULL if 'path' is invalid. */
core_updater_info_t *core_info_get_core_updater_info(const char *path);
core_updater_info_t *core_info_get_core_updater_info(const char *info_path);
void core_info_free_core_updater_info(core_updater_info_t *info);

void core_info_get_name(const char *path, char *s, size_t len,
const char *path_info, const char *dir_cores,
const char *exts, bool show_hidden_files,
bool get_display_name);

core_info_t *core_info_get(core_info_list_t *list, size_t i);

void core_info_free_current_core(core_info_state_t *p_coreinfo);
Expand All @@ -186,22 +166,20 @@ size_t core_info_count(void);
bool core_info_list_update_missing_firmware(core_info_ctx_firmware_t *info,
bool *set_missing_bios);

bool core_info_find(core_info_ctx_find_t *info);
bool core_info_find(const char *core_path,
core_info_t **core_info);

bool core_info_load(
core_info_ctx_find_t *info,
bool core_info_load(const char *core_path,
core_info_state_t *p_coreinfo);

bool core_info_database_supports_content_path(const char *database_path, const char *path);

bool core_info_database_match_archive_member(const char *database_path);

bool core_info_unsupported_content_path(const char *path);

void core_info_qsort(core_info_list_t *core_info_list, enum core_info_list_qsort_type qsort_type);

bool core_info_list_get_info(core_info_list_t *core_info_list,
core_info_t *out_info, const char *path);
core_info_t *out_info, const char *core_path);

bool core_info_hw_api_supported(core_info_t *info);

Expand All @@ -223,7 +201,7 @@ bool core_info_get_core_lock(const char *core_path, bool validate_path);

core_info_state_t *coreinfo_get_ptr(void);

bool core_info_core_file_id_is_equal(const char* core_path_a, const char* core_path_b);
bool core_info_core_file_id_is_equal(const char *core_path_a, const char *core_path_b);

RETRO_END_DECLS

Expand Down
21 changes: 8 additions & 13 deletions gfx/widgets/gfx_widget_load_content_animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ bool gfx_widget_start_load_content_animation(void)
const char *content_path = path_get(RARCH_PATH_CONTENT);
const char *core_path = path_get(RARCH_PATH_CORE);
playlist_t *playlist = playlist_get_cached();
core_info_t *core_info = NULL;

bool playlist_entry_found = false;
bool has_content = false;
bool has_system = false;
bool has_db_name = false;

core_info_ctx_find_t core_info_finder;
char icon_path[PATH_MAX_LENGTH];

icon_path[0] = '\0';
Expand All @@ -314,13 +314,10 @@ bool gfx_widget_start_load_content_animation(void)
return false;

/* Check core validity */
core_info_finder.inf = NULL;
core_info_finder.path = core_path;

if (!core_info_find(&core_info_finder))
if (!core_info_find(core_path, &core_info))
return false;

core_path = core_info_finder.inf->path;
core_path = core_info->path;

/* Parse content path
* > If we have a cached playlist, attempt to find
Expand Down Expand Up @@ -357,10 +354,8 @@ bool gfx_widget_start_load_content_animation(void)

/* Check whether core matches... */
if (string_is_empty(entry_core_file) ||
!string_starts_with_size(
entry_core_file,
core_info_finder.inf->core_file_id.str,
core_info_finder.inf->core_file_id.len))
!string_starts_with(entry_core_file,
core_info->core_file_id.str))
entry = NULL;
}
}
Expand Down Expand Up @@ -430,8 +425,8 @@ bool gfx_widget_start_load_content_animation(void)
if (!has_system)
{
/* Use core display name, if available */
if (!string_is_empty(core_info_finder.inf->display_name))
strlcpy(state->system_name, core_info_finder.inf->display_name,
if (!string_is_empty(core_info->display_name))
strlcpy(state->system_name, core_info->display_name,
sizeof(state->system_name));
/* Otherwise, just use 'RetroArch' as a fallback */
else
Expand Down Expand Up @@ -466,7 +461,7 @@ bool gfx_widget_start_load_content_animation(void)
{
const char *core_db_name = NULL;
struct string_list *databases_list =
core_info_finder.inf->databases_list;
core_info->databases_list;

/* We can only use the core db_name if the
* core is associated with exactly one database */
Expand Down
47 changes: 19 additions & 28 deletions menu/cbs/menu_cbs_get_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,16 @@ static void menu_action_setting_disp_set_label_core_updater_entry(
core_updater_list_get_filename(core_list, path, &entry) &&
!string_is_empty(entry->local_core_path))
{
core_info_ctx_find_t core_info;
core_info_t *core_info = NULL;

/* Check whether core is installed
* > Note: We search core_info here instead
* of calling path_is_valid() since we don't
* want to perform disk access every frame */
core_info.inf = NULL;
core_info.path = entry->local_core_path;

if (core_info_find(&core_info))
if (core_info_find(entry->local_core_path, &core_info))
{
/* Highlight locked cores */
if (core_info.inf->is_locked)
if (core_info->is_locked)
{
s[0] = '[';
s[1] = '#';
Expand Down Expand Up @@ -493,12 +490,12 @@ static void menu_action_setting_disp_set_label_core_manager_entry(
const char *path,
char *s2, size_t len2)
{
core_info_ctx_find_t core_info;
const char *alt = list->list[i].alt
? list->list[i].alt
: list->list[i].path;
*s = '\0';
*w = 0;
core_info_t *core_info = NULL;
const char *alt = list->list[i].alt
? list->list[i].alt
: list->list[i].path;
*s = '\0';
*w = 0;

if (alt)
strlcpy(s2, alt, len2);
Expand All @@ -507,11 +504,8 @@ static void menu_action_setting_disp_set_label_core_manager_entry(
* > Note: We search core_info here instead of
* calling core_info_get_core_lock() since we
* don't want to perform disk access every frame */
core_info.inf = NULL;
core_info.path = path;

if (core_info_find(&core_info) &&
core_info.inf->is_locked)
if (core_info_find(path, &core_info) &&
core_info->is_locked)
{
s[0] = '[';
s[1] = '!';
Expand All @@ -529,12 +523,12 @@ static void menu_action_setting_disp_set_label_core_lock(
const char *path,
char *s2, size_t len2)
{
core_info_ctx_find_t core_info;
const char *alt = list->list[i].alt
? list->list[i].alt
: list->list[i].path;
*s = '\0';
*w = 0;
core_info_t *core_info = NULL;
const char *alt = list->list[i].alt
? list->list[i].alt
: list->list[i].path;
*s = '\0';
*w = 0;

if (alt)
strlcpy(s2, alt, len2);
Expand All @@ -543,11 +537,8 @@ static void menu_action_setting_disp_set_label_core_lock(
* > Note: We search core_info here instead of
* calling core_info_get_core_lock() since we
* don't want to perform disk access every frame */
core_info.inf = NULL;
core_info.path = path;

if (core_info_find(&core_info) &&
core_info.inf->is_locked)
if (core_info_find(path, &core_info) &&
core_info->is_locked)
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ON), len);
else
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF), len);
Expand Down
Loading

0 comments on commit f4511f6

Please sign in to comment.