From a86977de3a3da79c87b7ca4b4cce217eabdb79e7 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 14 Jun 2015 17:11:48 +0200 Subject: [PATCH] (tasks) Use hashes --- tasks/task_database.c | 39 ++++++++++++++++++++++---------------- tasks/task_file_transfer.c | 18 ++++++++++++------ tasks/task_http.c | 20 +++++++++++++++---- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/tasks/task_database.c b/tasks/task_database.c index 3bca18b2e9..3bdb8be003 100644 --- a/tasks/task_database.c +++ b/tasks/task_database.c @@ -28,6 +28,8 @@ #define CB_DB_SCAN_FILE 0x70ce56d2U #define CB_DB_SCAN_FOLDER 0xde2bef8eU +#define HASH_EXTENSION_ZIP 0x0b88c7d8U + #ifdef HAVE_LIBRETRODB #ifdef HAVE_ZLIB @@ -78,35 +80,40 @@ static int database_info_iterate_playlist( database_state_handle_t *db_state, database_info_handle_t *db, const char *name) { + uint32_t extension_hash = 0; char parent_dir[PATH_MAX_LENGTH] = {0}; path_parent_dir(parent_dir); - if (!strcmp(path_get_extension(name), "zip")) + extension_hash = djb2_calculate(path_get_extension(name)); + + switch (extension_hash) { + case HASH_EXTENSION_ZIP: #ifdef HAVE_ZLIB - db->type = DATABASE_TYPE_ITERATE_ZIP; - memset(&db->state, 0, sizeof(zlib_transfer_t)); - db_state->zip_name[0] = '\0'; - db->state.type = ZLIB_TRANSFER_INIT; + db->type = DATABASE_TYPE_ITERATE_ZIP; + memset(&db->state, 0, sizeof(zlib_transfer_t)); + db_state->zip_name[0] = '\0'; + db->state.type = ZLIB_TRANSFER_INIT; - return 1; + return 1; #endif - } - else - { - ssize_t ret; - int read_from = read_file(name, (void**)&db_state->buf, &ret); + default: + { + ssize_t ret; + int read_from = read_file(name, (void**)&db_state->buf, &ret); - if (read_from != 1 || ret <= 0) - return 0; + if (read_from != 1 || ret <= 0) + return 0; #ifdef HAVE_ZLIB - db_state->crc = zlib_crc32_calculate(db_state->buf, ret); + db_state->crc = zlib_crc32_calculate(db_state->buf, ret); #endif - db->type = DATABASE_TYPE_CRC_LOOKUP; - return 1; + db->type = DATABASE_TYPE_CRC_LOOKUP; + return 1; + } + break; } return 0; diff --git a/tasks/task_file_transfer.c b/tasks/task_file_transfer.c index ac94222c34..2533a04674 100644 --- a/tasks/task_file_transfer.c +++ b/tasks/task_file_transfer.c @@ -15,14 +15,18 @@ #include +#include #include #include #include -#include +#include #include "../runloop_data.h" #include "tasks.h" +#define CB_MENU_WALLPAPER 0xb476e505U +#define CB_MENU_BOXART 0x68b307cdU + #ifdef HAVE_MENU #include "../menu/menu_driver.h" @@ -386,7 +390,7 @@ static int cb_nbio_image_menu_boxart(void *data, size_t len) static int rarch_main_data_nbio_iterate_poll(nbio_handle_t *nbio) { char elem0[PATH_MAX_LENGTH] = {0}; - char elem1[PATH_MAX_LENGTH] = {0}; + uint32_t cb_type_hash = 0; struct nbio_t* handle = NULL; struct string_list *str_list = NULL; const char *path = NULL; @@ -411,7 +415,7 @@ static int rarch_main_data_nbio_iterate_poll(nbio_handle_t *nbio) if (str_list->size > 0) strlcpy(elem0, str_list->elems[0].data, sizeof(elem0)); if (str_list->size > 1) - strlcpy(elem1, str_list->elems[1].data, sizeof(elem1)); + cb_type_hash = djb2_calculate(str_list->elems[1].data); handle = nbio_open(elem0, NBIO_READ); @@ -425,13 +429,15 @@ static int rarch_main_data_nbio_iterate_poll(nbio_handle_t *nbio) nbio->is_finished = false; nbio->cb = &cb_nbio_default; - if (elem1[0] != '\0') + switch (cb_type_hash) { #if defined(HAVE_MENU) && defined(HAVE_RPNG) - if (!strcmp(elem1, "cb_menu_wallpaper")) + case CB_MENU_WALLPAPER: nbio->cb = &cb_nbio_image_menu_wallpaper; - else if (!strcmp(elem1, "cb_menu_boxart")) + break; + case CB_MENU_BOXART: nbio->cb = &cb_nbio_image_menu_boxart; + break; #endif } diff --git a/tasks/task_http.c b/tasks/task_http.c index 8230e412d3..2b61cd1267 100644 --- a/tasks/task_http.c +++ b/tasks/task_http.c @@ -19,12 +19,16 @@ #include #include #include +#include #include "../file_ops.h" #include "../general.h" #include "../runloop_data.h" #include "tasks.h" +#define CB_CORE_UPDATER_DOWNLOAD 0x7412da7dU +#define CB_CORE_UPDATER_LIST 0x32fd4f01U + extern char core_updater_path[PATH_MAX_LENGTH]; int cb_core_updater_list(void *data_, size_t len); @@ -150,6 +154,7 @@ static int rarch_main_data_http_iterate_transfer_parse(http_handle_t *http) return 0; } + static int cb_http_conn_default(void *data_, size_t len) { http_handle_t *http = (http_handle_t*)data_; @@ -169,10 +174,17 @@ static int cb_http_conn_default(void *data_, size_t len) if (http->connection.elem1[0] != '\0') { - if (!strcmp(http->connection.elem1, "cb_core_updater_download")) - http->cb = &cb_core_updater_download; - if (!strcmp(http->connection.elem1, "cb_core_updater_list")) - http->cb = &cb_core_updater_list; + uint32_t label_hash = djb2_calculate(http->connection.elem1); + + switch (label_hash) + { + case CB_CORE_UPDATER_DOWNLOAD: + http->cb = &cb_core_updater_download; + break; + case CB_CORE_UPDATER_LIST: + http->cb = &cb_core_updater_list; + break; + } } return 0;