From b04a9261707335314640ef3bd63b0500d3b6433a Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Fri, 17 Feb 2023 17:49:36 +0100 Subject: [PATCH] (libretro-db) Further cleanups --- database_info.c | 8 ++---- libretro-db/rmsgpack.c | 42 +++++++++++++---------------- libretro-db/rmsgpack_dom.c | 55 ++++++++++++++++++-------------------- 3 files changed, 47 insertions(+), 58 deletions(-) diff --git a/database_info.c b/database_info.c index 937cfa2ece..c3fdb308c4 100644 --- a/database_info.c +++ b/database_info.c @@ -762,11 +762,6 @@ static int dir_entry_compare(const void *left, const void *right) return (int) r - (int) l; } -static void dir_list_prioritize(struct string_list *list) -{ - qsort(list->elems, list->size, sizeof(*list->elems), dir_entry_compare); -} - database_info_handle_t *database_info_dir_init(const char *dir, enum database_type type, retro_task_t *task, bool show_hidden_files) @@ -789,7 +784,8 @@ database_info_handle_t *database_info_dir_init(const char *dir, return NULL; } - dir_list_prioritize(list); + /* dir list prioritize */ + qsort(list->elems, list->size, sizeof(*list->elems), dir_entry_compare); db->status = DATABASE_STATUS_ITERATE; db->type = type; diff --git a/libretro-db/rmsgpack.c b/libretro-db/rmsgpack.c index 1c25d1959c..a1ae38da3f 100644 --- a/libretro-db/rmsgpack.c +++ b/libretro-db/rmsgpack.c @@ -66,34 +66,11 @@ #define _MPF_NIL 0xc0 static const uint8_t MPF_FIXMAP = _MPF_FIXMAP; -static const uint8_t MPF_MAP16 = _MPF_MAP16; static const uint8_t MPF_MAP32 = _MPF_MAP32; static const uint8_t MPF_FIXARRAY = _MPF_FIXARRAY; -static const uint8_t MPF_ARRAY16 = _MPF_ARRAY16; -static const uint8_t MPF_ARRAY32 = _MPF_ARRAY32; static const uint8_t MPF_FIXSTR = _MPF_FIXSTR; -static const uint8_t MPF_STR8 = _MPF_STR8; -static const uint8_t MPF_STR16 = _MPF_STR16; -static const uint8_t MPF_STR32 = _MPF_STR32; - -static const uint8_t MPF_BIN8 = _MPF_BIN8; -static const uint8_t MPF_BIN16 = _MPF_BIN16; -static const uint8_t MPF_BIN32 = _MPF_BIN32; - -static const uint8_t MPF_FALSE = _MPF_FALSE; -static const uint8_t MPF_TRUE = _MPF_TRUE; - -static const uint8_t MPF_INT8 = _MPF_INT8; -static const uint8_t MPF_INT16 = _MPF_INT16; -static const uint8_t MPF_INT32 = _MPF_INT32; -static const uint8_t MPF_INT64 = _MPF_INT64; - -static const uint8_t MPF_UINT8 = _MPF_UINT8; -static const uint8_t MPF_UINT16 = _MPF_UINT16; -static const uint8_t MPF_UINT32 = _MPF_UINT32; -static const uint8_t MPF_UINT64 = _MPF_UINT64; static const uint8_t MPF_NIL = _MPF_NIL; @@ -101,6 +78,7 @@ int rmsgpack_write_array_header(RFILE *fd, uint32_t size) { uint16_t tmp_i16; uint32_t tmp_i32; + static const uint8_t MPF_ARRAY32 = _MPF_ARRAY32; if (size < 16) { @@ -111,6 +89,7 @@ int rmsgpack_write_array_header(RFILE *fd, uint32_t size) } else if (size == (uint16_t)size) { + static const uint8_t MPF_ARRAY16 = _MPF_ARRAY16; if (filestream_write(fd, &MPF_ARRAY16, sizeof(MPF_ARRAY16)) == -1) return -1; tmp_i16 = swap_if_little16(size); @@ -144,6 +123,7 @@ int rmsgpack_write_map_header(RFILE *fd, uint32_t size) } else if (size == (uint16_t)size) { + static const uint8_t MPF_MAP16 = _MPF_MAP16; if (filestream_write(fd, &MPF_MAP16, sizeof(MPF_MAP16)) == -1) return -1; tmp_i16 = swap_if_little16(size); @@ -176,6 +156,7 @@ int rmsgpack_write_string(RFILE *fd, const char *s, uint32_t len) } else if (len == (uint8_t)len) { + static const uint8_t MPF_STR8 = _MPF_STR8; if (filestream_write(fd, &MPF_STR8, sizeof(MPF_STR8)) == -1) return -1; tmp_i8 = (uint8_t)len; @@ -185,6 +166,7 @@ int rmsgpack_write_string(RFILE *fd, const char *s, uint32_t len) } else if (len == (uint16_t)len) { + static const uint8_t MPF_STR16 = _MPF_STR16; if (filestream_write(fd, &MPF_STR16, sizeof(MPF_STR16)) == -1) return -1; tmp_i16 = swap_if_little16(len); @@ -194,6 +176,7 @@ int rmsgpack_write_string(RFILE *fd, const char *s, uint32_t len) } else { + static const uint8_t MPF_STR32 = _MPF_STR32; if (filestream_write(fd, &MPF_STR32, sizeof(MPF_STR32)) == -1) return -1; tmp_i32 = swap_if_little32(len); @@ -218,6 +201,7 @@ int rmsgpack_write_bin(RFILE *fd, const void *s, uint32_t len) if (len == (uint8_t)len) { + static const uint8_t MPF_BIN8 = _MPF_BIN8; if (filestream_write(fd, &MPF_BIN8, sizeof(MPF_BIN8)) == -1) return -1; tmp_i8 = (uint8_t)len; @@ -226,6 +210,7 @@ int rmsgpack_write_bin(RFILE *fd, const void *s, uint32_t len) } else if (len == (uint16_t)len) { + static const uint8_t MPF_BIN16 = _MPF_BIN16; if (filestream_write(fd, &MPF_BIN16, sizeof(MPF_BIN16)) == -1) return -1; tmp_i16 = swap_if_little16(len); @@ -234,6 +219,7 @@ int rmsgpack_write_bin(RFILE *fd, const void *s, uint32_t len) } else { + static const uint8_t MPF_BIN32 = _MPF_BIN32; if (filestream_write(fd, &MPF_BIN32, sizeof(MPF_BIN32)) == -1) return -1; tmp_i32 = swap_if_little32(len); @@ -254,8 +240,10 @@ int rmsgpack_write_nil(RFILE *fd) int rmsgpack_write_bool(RFILE *fd, int value) { + static const uint8_t MPF_FALSE = _MPF_FALSE; if (value) { + static const uint8_t MPF_TRUE = _MPF_TRUE; if (filestream_write(fd, &MPF_TRUE, sizeof(MPF_TRUE)) == -1) return -1; } @@ -288,6 +276,7 @@ int rmsgpack_write_int(RFILE *fd, int64_t value) } else if (value == (int8_t)value) { + static const uint8_t MPF_INT8 = _MPF_INT8; if (filestream_write(fd, &MPF_INT8, sizeof(MPF_INT8)) == -1) return -1; @@ -298,6 +287,7 @@ int rmsgpack_write_int(RFILE *fd, int64_t value) } else if (value == (int16_t)value) { + static const uint8_t MPF_INT16 = _MPF_INT16; if (filestream_write(fd, &MPF_INT16, sizeof(MPF_INT16)) == -1) return -1; @@ -308,6 +298,7 @@ int rmsgpack_write_int(RFILE *fd, int64_t value) } else if (value == (int32_t)value) { + static const uint8_t MPF_INT32 = _MPF_INT32; if (filestream_write(fd, &MPF_INT32, sizeof(MPF_INT32)) == -1) return -1; @@ -318,6 +309,7 @@ int rmsgpack_write_int(RFILE *fd, int64_t value) } else { + static const uint8_t MPF_INT64 = _MPF_INT64; if (filestream_write(fd, &MPF_INT64, sizeof(MPF_INT64)) == -1) return -1; @@ -339,6 +331,7 @@ int rmsgpack_write_uint(RFILE *fd, uint64_t value) if (value == (uint8_t)value) { + static const uint8_t MPF_UINT8 = _MPF_UINT8; if (filestream_write(fd, &MPF_UINT8, sizeof(MPF_UINT8)) == -1) return -1; @@ -349,6 +342,7 @@ int rmsgpack_write_uint(RFILE *fd, uint64_t value) } else if (value == (uint16_t)value) { + static const uint8_t MPF_UINT16 = _MPF_UINT16; if (filestream_write(fd, &MPF_UINT16, sizeof(MPF_UINT16)) == -1) return -1; @@ -359,6 +353,7 @@ int rmsgpack_write_uint(RFILE *fd, uint64_t value) } else if (value == (uint32_t)value) { + static const uint8_t MPF_UINT32 = _MPF_UINT32; if (filestream_write(fd, &MPF_UINT32, sizeof(MPF_UINT32)) == -1) return -1; @@ -369,6 +364,7 @@ int rmsgpack_write_uint(RFILE *fd, uint64_t value) } else { + static const uint8_t MPF_UINT64 = _MPF_UINT64; if (filestream_write(fd, &MPF_UINT64, sizeof(MPF_UINT64)) == -1) return -1; diff --git a/libretro-db/rmsgpack_dom.c b/libretro-db/rmsgpack_dom.c index 15ce4d3637..74ace3400e 100644 --- a/libretro-db/rmsgpack_dom.c +++ b/libretro-db/rmsgpack_dom.c @@ -34,16 +34,16 @@ struct dom_reader_state { - int i; - struct rmsgpack_dom_value *stack[MAX_DEPTH]; + int i; + struct rmsgpack_dom_value *stack[MAX_DEPTH]; }; static struct rmsgpack_dom_value *dom_reader_state_pop( struct dom_reader_state *s) { - struct rmsgpack_dom_value *v = s->stack[s->i]; - s->i--; - return v; + struct rmsgpack_dom_value *v = s->stack[s->i]; + s->i--; + return v; } static int dom_reader_state_push( @@ -59,42 +59,40 @@ static int dom_reader_state_push( static int dom_read_nil(void *data) { struct dom_reader_state *dom_state = (struct dom_reader_state *)data; - struct rmsgpack_dom_value *v = + struct rmsgpack_dom_value *v = (struct rmsgpack_dom_value*)dom_reader_state_pop(dom_state); - v->type = RDT_NULL; + v->type = RDT_NULL; return 0; } static int dom_read_bool(int value, void *data) { struct dom_reader_state *dom_state = (struct dom_reader_state *)data; - struct rmsgpack_dom_value *v = + struct rmsgpack_dom_value *v = (struct rmsgpack_dom_value*)dom_reader_state_pop(dom_state); - v->type = RDT_BOOL; - v->val.bool_ = value; + v->type = RDT_BOOL; + v->val.bool_ = value; return 0; } static int dom_read_int(int64_t value, void *data) { struct dom_reader_state *dom_state = (struct dom_reader_state *)data; - struct rmsgpack_dom_value *v = + struct rmsgpack_dom_value *v = (struct rmsgpack_dom_value*)dom_reader_state_pop(dom_state); - - v->type = RDT_INT; - v->val.int_ = value; + v->type = RDT_INT; + v->val.int_ = value; return 0; } static int dom_read_uint(uint64_t value, void *data) { struct dom_reader_state *dom_state = (struct dom_reader_state *)data; - struct rmsgpack_dom_value *v = + struct rmsgpack_dom_value *v = (struct rmsgpack_dom_value*)dom_reader_state_pop(dom_state); - - v->type = RDT_UINT; - v->val.uint_ = value; + v->type = RDT_UINT; + v->val.uint_ = value; return 0; } @@ -152,7 +150,7 @@ static int dom_read_map_start(uint32_t len, void *data) static int dom_read_array_start(uint32_t len, void *data) { - unsigned i; + int i; struct dom_reader_state *dom_state = (struct dom_reader_state *)data; struct rmsgpack_dom_value *v = dom_reader_state_pop(dom_state); struct rmsgpack_dom_value *items = NULL; @@ -178,8 +176,7 @@ static int dom_read_array_start(uint32_t len, void *data) void rmsgpack_dom_value_free(struct rmsgpack_dom_value *v) { - unsigned i; - + int i; switch (v->type) { case RDT_STRING: @@ -249,15 +246,15 @@ int rmsgpack_dom_value_cmp( case RDT_UINT: return (a->val.uint_ == b->val.uint_) ? 0 : 1; case RDT_STRING: - if (a->val.string.len != b->val.string.len) - return 1; - return strncmp(a->val.string.buff, - b->val.string.buff, a->val.string.len); + if (a->val.string.len == b->val.string.len) + return strncmp(a->val.string.buff, + b->val.string.buff, a->val.string.len); + break; case RDT_BINARY: - if (a->val.binary.len != b->val.binary.len) - return 1; - return memcmp(a->val.binary.buff, - b->val.binary.buff, a->val.binary.len); + if (a->val.binary.len == b->val.binary.len) + return memcmp(a->val.binary.buff, + b->val.binary.buff, a->val.binary.len); + break; case RDT_MAP: if (a->val.map.len != b->val.map.len) return 1;