mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
Merge pull request #1790 from heuripedes/master
Minor performance improvements
This commit is contained in:
commit
38a1c82731
@ -266,35 +266,38 @@ static void gl_raster_font_render_message(
|
||||
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y,
|
||||
unsigned text_align)
|
||||
{
|
||||
//If the font height is not supported just draw as usual
|
||||
if (!font->font_driver->get_line_height)
|
||||
{
|
||||
gl_raster_font_render_line(font, msg, strlen(msg), scale, color, pos_x, pos_y, text_align);
|
||||
return;
|
||||
}
|
||||
|
||||
int lines = 0;
|
||||
float line_height = scale * 1/(float)font->font_driver->get_line_height(font->font_data);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const char *delim = strchr(msg, '\n');
|
||||
|
||||
//Draw the line
|
||||
if (delim)
|
||||
{
|
||||
unsigned msg_len = delim - msg;
|
||||
gl_raster_font_render_line(font, msg, msg_len, scale, color, pos_x, pos_y - (float)lines*line_height, text_align);
|
||||
msg += msg_len + 1;
|
||||
lines++;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned msg_len = strlen(msg);
|
||||
gl_raster_font_render_line(font, msg, msg_len, scale, color, pos_x, pos_y - (float)lines*line_height, text_align);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!msg || !*msg || !font->gl)
|
||||
return;
|
||||
|
||||
//If the font height is not supported just draw as usual
|
||||
if (!font->font_driver->get_line_height)
|
||||
{
|
||||
gl_raster_font_render_line(font, msg, strlen(msg), scale, color, pos_x, pos_y, text_align);
|
||||
return;
|
||||
}
|
||||
|
||||
int lines = 0;
|
||||
float line_height = scale * 1/(float)font->font_driver->get_line_height(font->font_data);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const char *delim = strchr(msg, '\n');
|
||||
|
||||
//Draw the line
|
||||
if (delim)
|
||||
{
|
||||
unsigned msg_len = delim - msg;
|
||||
gl_raster_font_render_line(font, msg, msg_len, scale, color, pos_x, pos_y - (float)lines*line_height, text_align);
|
||||
msg += msg_len + 1;
|
||||
lines++;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned msg_len = strlen(msg);
|
||||
gl_raster_font_render_line(font, msg, msg_len, scale, color, pos_x, pos_y - (float)lines*line_height, text_align);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void gl_raster_font_setup_viewport(gl_raster_t *font, bool full_screen)
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <file/file_path.h>
|
||||
#include <retro_miscellaneous.h>
|
||||
#include <string/string_list.h>
|
||||
#include <rhash.h>
|
||||
|
||||
#if !defined(_WIN32) && !defined(__CELLOS_LV2__) && !defined(_XBOX)
|
||||
#include <sys/param.h> /* PATH_MAX */
|
||||
@ -327,6 +328,7 @@ static bool parse_line(config_file_t *conf,
|
||||
}
|
||||
key[idx] = '\0';
|
||||
list->key = key;
|
||||
list->key_hash = djb2_calculate(key);
|
||||
|
||||
list->value = extract_value(line, true);
|
||||
if (!list->value)
|
||||
@ -524,178 +526,152 @@ void config_file_free(config_file_t *conf)
|
||||
free(conf);
|
||||
}
|
||||
|
||||
static struct config_entry_list *config_get_entry(const config_file_t *conf,
|
||||
const char *key, struct config_entry_list **prev)
|
||||
{
|
||||
struct config_entry_list *entry;
|
||||
struct config_entry_list *previous = NULL;
|
||||
|
||||
uint32_t hash = djb2_calculate(key);
|
||||
|
||||
if (prev)
|
||||
previous = *prev;
|
||||
|
||||
for (entry = conf->entries; entry; entry = entry->next)
|
||||
{
|
||||
if (hash == entry->key_hash && strcmp(key, entry->key) == 0)
|
||||
return entry;
|
||||
|
||||
previous = entry;
|
||||
}
|
||||
|
||||
if (prev)
|
||||
*prev = previous;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool config_get_double(config_file_t *conf, const char *key, double *in)
|
||||
{
|
||||
struct config_entry_list *list = conf->entries;
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
|
||||
while (list)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
*in = strtod(list->value, NULL);
|
||||
return true;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
return false;
|
||||
if (entry)
|
||||
*in = strtod(entry->value, NULL);
|
||||
|
||||
return entry != NULL;
|
||||
}
|
||||
|
||||
bool config_get_float(config_file_t *conf, const char *key, float *in)
|
||||
{
|
||||
struct config_entry_list *list = conf->entries;
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
|
||||
while (list)
|
||||
if (entry)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
/* strtof() is C99/POSIX. Just use the more portable kind. */
|
||||
*in = (float)strtod(list->value, NULL);
|
||||
return true;
|
||||
}
|
||||
list = list->next;
|
||||
/* strtof() is C99/POSIX. Just use the more portable kind. */
|
||||
*in = (float)strtod(entry->value, NULL);
|
||||
}
|
||||
return false;
|
||||
|
||||
return entry != NULL;
|
||||
}
|
||||
|
||||
bool config_get_int(config_file_t *conf, const char *key, int *in)
|
||||
{
|
||||
struct config_entry_list *list = conf->entries;
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
errno = 0;
|
||||
|
||||
while (list)
|
||||
if (entry)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
int val;
|
||||
errno = 0;
|
||||
val = strtol(list->value, NULL, 0);
|
||||
if (errno == 0)
|
||||
{
|
||||
*in = val;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
list = list->next;
|
||||
int val = strtol(entry->value, NULL, 0);
|
||||
|
||||
if (errno == 0)
|
||||
*in = val;
|
||||
}
|
||||
return false;
|
||||
|
||||
return entry != NULL && errno == 0;
|
||||
}
|
||||
|
||||
bool config_get_uint64(config_file_t *conf, const char *key, uint64_t *in)
|
||||
{
|
||||
struct config_entry_list *list = conf->entries;
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
errno = 0;
|
||||
|
||||
while (list)
|
||||
if (entry)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
uint64_t val;
|
||||
errno = 0;
|
||||
val = strtoull(list->value, NULL, 0);
|
||||
if (errno == 0)
|
||||
{
|
||||
*in = val;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
list = list->next;
|
||||
uint64_t val = strtoull(entry->value, NULL, 0);
|
||||
|
||||
if (errno == 0)
|
||||
*in = val;
|
||||
}
|
||||
return false;
|
||||
|
||||
return entry != NULL && errno == 0;
|
||||
}
|
||||
|
||||
bool config_get_uint(config_file_t *conf, const char *key, unsigned *in)
|
||||
{
|
||||
struct config_entry_list *list = conf->entries;
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
errno = 0;
|
||||
|
||||
while (list != NULL)
|
||||
if (entry)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
unsigned val;
|
||||
errno = 0;
|
||||
val = strtoul(list->value, NULL, 0);
|
||||
if (errno == 0)
|
||||
{
|
||||
*in = val;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
list = list->next;
|
||||
unsigned val = strtoul(entry->value, NULL, 0);
|
||||
|
||||
if (errno == 0)
|
||||
*in = val;
|
||||
}
|
||||
|
||||
return false;
|
||||
return entry != NULL && errno == 0;
|
||||
}
|
||||
|
||||
bool config_get_hex(config_file_t *conf, const char *key, unsigned *in)
|
||||
{
|
||||
struct config_entry_list *list = conf->entries;
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
errno = 0;
|
||||
|
||||
while (list)
|
||||
if (entry)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
unsigned val;
|
||||
errno = 0;
|
||||
val = strtoul(list->value, NULL, 16);
|
||||
if (errno == 0)
|
||||
{
|
||||
*in = val;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
list = list->next;
|
||||
unsigned val = strtoul(entry->value, NULL, 16);
|
||||
|
||||
if (errno == 0)
|
||||
*in = val;
|
||||
}
|
||||
return false;
|
||||
|
||||
return entry != NULL && errno == 0;
|
||||
}
|
||||
|
||||
bool config_get_char(config_file_t *conf, const char *key, char *in)
|
||||
{
|
||||
struct config_entry_list *list = conf->entries;
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
|
||||
while (list)
|
||||
if (entry)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
if (list->value[0] && list->value[1])
|
||||
return false;
|
||||
*in = *list->value;
|
||||
return true;
|
||||
}
|
||||
list = list->next;
|
||||
if (entry->value[0] && entry->value[1])
|
||||
return false;
|
||||
|
||||
*in = *entry->value;
|
||||
}
|
||||
return false;
|
||||
|
||||
return entry != NULL;
|
||||
}
|
||||
|
||||
bool config_get_string(config_file_t *conf, const char *key, char **str)
|
||||
{
|
||||
struct config_entry_list *list = conf->entries;
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
|
||||
while (list)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
*str = strdup(list->value);
|
||||
return true;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
return false;
|
||||
if (entry)
|
||||
*str = strdup(entry->value);
|
||||
|
||||
return entry != NULL;
|
||||
}
|
||||
|
||||
bool config_get_array(config_file_t *conf, const char *key,
|
||||
char *buf, size_t size)
|
||||
{
|
||||
struct config_entry_list *list = conf->entries;
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
|
||||
while (list)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
return strlcpy(buf, list->value, size) < size;
|
||||
list = list->next;
|
||||
}
|
||||
return false;
|
||||
if (entry)
|
||||
return strlcpy(buf, entry->value, size) < size;
|
||||
|
||||
return entry != NULL;
|
||||
}
|
||||
|
||||
bool config_get_path(config_file_t *conf, const char *key,
|
||||
@ -704,77 +680,60 @@ bool config_get_path(config_file_t *conf, const char *key,
|
||||
#if defined(RARCH_CONSOLE)
|
||||
return config_get_array(conf, key, buf, size);
|
||||
#else
|
||||
struct config_entry_list *list = conf->entries;
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
|
||||
while (list)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
fill_pathname_expand_special(buf, list->value, size);
|
||||
return true;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
return false;
|
||||
if (entry)
|
||||
fill_pathname_expand_special(buf, entry->value, size);
|
||||
|
||||
return entry != NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool config_get_bool(config_file_t *conf, const char *key, bool *in)
|
||||
{
|
||||
struct config_entry_list *list = conf->entries;
|
||||
const struct config_entry_list *entry = config_get_entry(conf, key, NULL);
|
||||
|
||||
while (list)
|
||||
if (entry)
|
||||
{
|
||||
if (strcmp(key, list->key) == 0)
|
||||
{
|
||||
if (strcasecmp(list->value, "true") == 0)
|
||||
*in = true;
|
||||
else if (strcasecmp(list->value, "1") == 0)
|
||||
*in = true;
|
||||
else if (strcasecmp(list->value, "false") == 0)
|
||||
*in = false;
|
||||
else if (strcasecmp(list->value, "0") == 0)
|
||||
*in = false;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
list = list->next;
|
||||
if (strcasecmp(entry->value, "true") == 0)
|
||||
*in = true;
|
||||
else if (strcasecmp(entry->value, "1") == 0)
|
||||
*in = true;
|
||||
else if (strcasecmp(entry->value, "false") == 0)
|
||||
*in = false;
|
||||
else if (strcasecmp(entry->value, "0") == 0)
|
||||
*in = false;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
return entry != NULL;
|
||||
}
|
||||
|
||||
void config_set_string(config_file_t *conf, const char *key, const char *val)
|
||||
{
|
||||
struct config_entry_list *elem = NULL;
|
||||
struct config_entry_list *list = conf->entries;
|
||||
struct config_entry_list *last = list;
|
||||
while (list)
|
||||
{
|
||||
if (!list->readonly && (strcmp(key, list->key) == 0))
|
||||
{
|
||||
free(list->value);
|
||||
list->value = strdup(val);
|
||||
return;
|
||||
}
|
||||
struct config_entry_list *last = conf->entries;
|
||||
struct config_entry_list *entry = config_get_entry(conf, key, &last);
|
||||
|
||||
last = list;
|
||||
list = list->next;
|
||||
if (entry && !entry->readonly)
|
||||
{
|
||||
free(entry->value);
|
||||
entry->value = strdup(val);
|
||||
return;
|
||||
}
|
||||
|
||||
elem = (struct config_entry_list*)calloc(1, sizeof(*elem));
|
||||
entry = (struct config_entry_list*)calloc(1, sizeof(*entry));
|
||||
|
||||
if (!elem)
|
||||
if (!entry)
|
||||
return;
|
||||
|
||||
elem->key = strdup(key);
|
||||
elem->value = strdup(val);
|
||||
entry->key = strdup(key);
|
||||
entry->value = strdup(val);
|
||||
|
||||
if (last)
|
||||
last->next = elem;
|
||||
last->next = entry;
|
||||
else
|
||||
conf->entries = elem;
|
||||
conf->entries = entry;
|
||||
}
|
||||
|
||||
void config_set_path(config_file_t *conf, const char *entry, const char *val)
|
||||
|
@ -40,6 +40,8 @@ struct config_entry_list
|
||||
bool readonly;
|
||||
char *key;
|
||||
char *value;
|
||||
uint32_t key_hash;
|
||||
|
||||
struct config_entry_list *next;
|
||||
};
|
||||
|
||||
|
@ -477,7 +477,7 @@ static void parse_input(int argc, char *argv[])
|
||||
{ "size", 1, &val, RA_OPT_SIZE },
|
||||
{ "verbose", 0, NULL, 'v' },
|
||||
{ "config", 1, NULL, 'c' },
|
||||
{ "appendconfig", 1, &val, 'C' },
|
||||
{ "appendconfig", 1, &val, RA_OPT_APPENDCONFIG },
|
||||
{ "nodevice", 1, NULL, 'N' },
|
||||
{ "dualanalog", 1, NULL, 'A' },
|
||||
{ "device", 1, NULL, 'd' },
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "../libretro-common/queues/fifo_buffer.c"
|
||||
#include "../libretro-common/file/config_file.c"
|
||||
#include "../libretro-common/file/file_path.c"
|
||||
#include "../libretro-common/hash/rhash.c"
|
||||
#include "../file_path_special.c"
|
||||
#include "../libretro-common/string/string_list.c"
|
||||
#include "../libretro-common/compat/compat.c"
|
||||
|
Loading…
x
Reference in New Issue
Block a user