Optimize config_get_bool

This commit is contained in:
twinaphex 2020-06-25 03:03:42 +02:00
parent 8fccac666e
commit 1c38dc67c2
2 changed files with 30 additions and 13 deletions

View File

@ -415,6 +415,23 @@ static bool parse_line(config_file_t *conf,
return false; return false;
} }
if (
string_is_equal(list->value, "true")
|| string_is_equal(list->value, "1")
)
{
list->type = CONFIG_FILE_ENTRY_TYPE_BOOL;
list->value_bool = true;
}
else if (
string_is_equal(list->value, "false")
|| string_is_equal(list->value, "0")
)
{
list->type = CONFIG_FILE_ENTRY_TYPE_BOOL;
list->value_bool = false;
}
return true; return true;
} }
@ -878,21 +895,13 @@ bool config_get_bool(config_file_t *conf, const char *key, bool *in)
{ {
const struct config_entry_list *entry = config_get_entry(conf, key, NULL); const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
if (entry) if (entry && entry->type == CONFIG_FILE_ENTRY_TYPE_BOOL)
{ {
if (string_is_equal(entry->value, "true")) *in = entry->value_bool;
*in = true; return true;
else if (string_is_equal(entry->value, "1"))
*in = true;
else if (string_is_equal(entry->value, "false"))
*in = false;
else if (string_is_equal(entry->value, "0"))
*in = false;
else
return false;
} }
return entry != NULL; return false;
} }
void config_set_string(config_file_t *conf, const char *key, const char *val) void config_set_string(config_file_t *conf, const char *key, const char *val)

View File

@ -51,6 +51,13 @@ RETRO_BEGIN_DECLS
base->var = tmp; \ base->var = tmp; \
} while(0) } while(0)
enum config_file_entry_type
{
CONFIG_FILE_ENTRY_TYPE_DONTCARE = 0,
CONFIG_FILE_ENTRY_TYPE_BOOL
};
struct config_file struct config_file
{ {
char *path; char *path;
@ -120,10 +127,11 @@ struct config_entry_list
char *key; char *key;
char *value; char *value;
enum config_file_entry_type type;
bool value_bool;
struct config_entry_list *next; struct config_entry_list *next;
}; };
struct config_file_entry struct config_file_entry
{ {
const char *key; const char *key;