mirror of
https://github.com/libretro/RetroArch
synced 2025-04-01 13:20:43 +00:00
Core info list iteration was calling path_stat two times on the same
paths - unnecessary file I/O is an issue with UWP/WinRT so let's cut this down to only one path_stat. config_file_read function created - acts the same as config_file_new except it doesn't check if the path provided is actually a directory, which in turn would lead to another path_stat call
This commit is contained in:
parent
b41384a0d0
commit
69168ec6bc
@ -286,7 +286,7 @@ static core_info_list_t *core_info_list_new(const char *path,
|
||||
char *tmp = NULL;
|
||||
bool tmp_bool = false;
|
||||
unsigned count = 0;
|
||||
config_file_t *conf = config_file_new(info_path);
|
||||
config_file_t *conf = config_file_read(info_path);
|
||||
|
||||
free(info_path);
|
||||
|
||||
|
@ -69,7 +69,7 @@ struct config_include_list
|
||||
};
|
||||
|
||||
static config_file_t *config_file_new_internal(
|
||||
const char *path, unsigned depth, config_file_cb_t *cb);
|
||||
const char *path, unsigned depth, config_file_cb_t *cb, bool no_checks);
|
||||
|
||||
static int config_sort_compare_func(struct config_entry_list *a,
|
||||
struct config_entry_list *b)
|
||||
@ -270,7 +270,8 @@ static void add_child_list(config_file_t *parent, config_file_t *child)
|
||||
parent->tail = NULL;
|
||||
}
|
||||
|
||||
static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb)
|
||||
static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb,
|
||||
bool no_checks)
|
||||
{
|
||||
char real_path[PATH_MAX_LENGTH];
|
||||
config_file_t *sub_conf = NULL;
|
||||
@ -317,7 +318,7 @@ static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb)
|
||||
#endif
|
||||
|
||||
sub_conf = (config_file_t*)
|
||||
config_file_new_internal(real_path, conf->include_depth + 1, cb);
|
||||
config_file_new_internal(real_path, conf->include_depth + 1, cb, no_checks);
|
||||
if (!sub_conf)
|
||||
return;
|
||||
|
||||
@ -327,18 +328,14 @@ static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb)
|
||||
}
|
||||
|
||||
static bool parse_line(config_file_t *conf,
|
||||
struct config_entry_list *list, char *line, config_file_cb_t *cb)
|
||||
struct config_entry_list *list, char *line, config_file_cb_t *cb,
|
||||
bool no_checks)
|
||||
{
|
||||
char *comment = NULL;
|
||||
char *key_tmp = NULL;
|
||||
size_t cur_size = 8;
|
||||
size_t idx = 0;
|
||||
char *key = (char*)malloc(9);
|
||||
|
||||
if (!key)
|
||||
return false;
|
||||
|
||||
comment = strip_comment(line);
|
||||
char *comment = strip_comment(line);
|
||||
|
||||
/* Starting line with #include includes config files. */
|
||||
if (comment == line)
|
||||
@ -354,7 +351,7 @@ static bool parse_line(config_file_t *conf,
|
||||
if (conf->include_depth >= MAX_INCLUDE_DEPTH)
|
||||
fprintf(stderr, "!!! #include depth exceeded for config. Might be a cycle.\n");
|
||||
else
|
||||
add_sub_conf(conf, path, cb);
|
||||
add_sub_conf(conf, path, cb, no_checks);
|
||||
free(path);
|
||||
}
|
||||
goto error;
|
||||
@ -399,7 +396,7 @@ error:
|
||||
}
|
||||
|
||||
static config_file_t *config_file_new_internal(
|
||||
const char *path, unsigned depth, config_file_cb_t *cb)
|
||||
const char *path, unsigned depth, config_file_cb_t *cb, bool no_checks)
|
||||
{
|
||||
RFILE *file = NULL;
|
||||
struct config_file *conf = (struct config_file*)malloc(sizeof(*conf));
|
||||
@ -417,8 +414,9 @@ static config_file_t *config_file_new_internal(
|
||||
if (!path || !*path)
|
||||
return conf;
|
||||
#if !defined(ORBIS)
|
||||
if (path_is_directory(path))
|
||||
goto error;
|
||||
if (!no_checks)
|
||||
if (path_is_directory(path))
|
||||
goto error;
|
||||
#endif
|
||||
conf->path = strdup(path);
|
||||
if (!conf->path)
|
||||
@ -460,7 +458,7 @@ static config_file_t *config_file_new_internal(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (*line && parse_line(conf, list, line, cb))
|
||||
if (*line && parse_line(conf, list, line, cb, no_checks))
|
||||
{
|
||||
if (conf->entries)
|
||||
conf->tail->next = list;
|
||||
@ -550,8 +548,9 @@ bool config_append_file(config_file_t *conf, const char *path)
|
||||
config_file_t *config_file_new_from_string(const char *from_string)
|
||||
{
|
||||
size_t i;
|
||||
bool no_checks = false;
|
||||
struct string_list *lines = NULL;
|
||||
struct config_file *conf = (struct config_file*)malloc(sizeof(*conf));
|
||||
struct config_file *conf = (struct config_file*)malloc(sizeof(*conf));
|
||||
if (!conf)
|
||||
return NULL;
|
||||
|
||||
@ -589,7 +588,7 @@ config_file_t *config_file_new_from_string(const char *from_string)
|
||||
|
||||
if (line && conf)
|
||||
{
|
||||
if (*line && parse_line(conf, list, line, NULL))
|
||||
if (*line && parse_line(conf, list, line, NULL, no_checks))
|
||||
{
|
||||
if (conf->entries)
|
||||
conf->tail->next = list;
|
||||
@ -611,11 +610,16 @@ config_file_t *config_file_new_from_string(const char *from_string)
|
||||
|
||||
config_file_t *config_file_new_with_callback(const char *path, config_file_cb_t *cb)
|
||||
{
|
||||
return config_file_new_internal(path, 0, cb);
|
||||
return config_file_new_internal(path, 0, cb, false);
|
||||
}
|
||||
config_file_t *config_file_new(const char *path)
|
||||
{
|
||||
return config_file_new_internal(path, 0, NULL);
|
||||
return config_file_new_internal(path, 0, NULL, false);
|
||||
}
|
||||
|
||||
config_file_t *config_file_read(const char *path)
|
||||
{
|
||||
return config_file_new_internal(path, 0, NULL, true);
|
||||
}
|
||||
|
||||
static struct config_entry_list *config_get_entry(const config_file_t *conf,
|
||||
|
@ -86,6 +86,11 @@ typedef struct config_file_cb config_file_cb_t ;
|
||||
* NULL path will create an empty config file. */
|
||||
config_file_t *config_file_new(const char *path);
|
||||
|
||||
/* Is the same as config_file_new, with the only difference that
|
||||
* it doesn't check if the path provided is a directory. This can
|
||||
* be significantly faster on platforms where file I/O is slow */
|
||||
config_file_t *config_file_read(const char *path);
|
||||
|
||||
/* Loads a config file. Returns NULL if file doesn't exist.
|
||||
* NULL path will create an empty config file.
|
||||
* Includes cb callbacks to run custom code during config file processing.*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user