From 26d6aee1eb064a533534dbc158a2085a887658aa Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 28 Apr 2019 17:23:11 +0200 Subject: [PATCH] Start using string_is_equal_memcmp and string_is_equal_memcmp_fast --- configuration.c | 60 +++++------ database_info.c | 62 ++++++------ gfx/drivers_shader/glslang_util.cpp | 3 +- gfx/video_driver.c | 24 +++-- gfx/video_shader_parse.c | 41 +++++--- input/input_driver.c | 19 ++-- intl/msg_hash_us.c | 2 +- libretro-common/file/config_file.c | 11 +- libretro-common/include/string/stdstring.h | 13 +++ menu/drivers/menu_generic.c | 27 ++--- menu/drivers/xmb.c | 42 ++++---- menu/menu_displaylist.c | 27 +++-- playlist.c | 50 +++++----- retroarch.c | 27 ++--- setting_list.c | 29 +++--- tasks/task_database.c | 111 +++++++++++---------- tasks/task_database_cue.c | 56 +++++------ 17 files changed, 324 insertions(+), 280 deletions(-) diff --git a/configuration.c b/configuration.c index 71f92e3372..1962190715 100644 --- a/configuration.c +++ b/configuration.c @@ -2537,29 +2537,31 @@ error: #if defined(HAVE_MENU) && defined(HAVE_RGUI) static bool check_menu_driver_compatibility(void) { - settings_t *settings = config_get_ptr(); - char *video_driver = settings->arrays.video_driver; - char *menu_driver = settings->arrays.menu_driver; + settings_t *settings = config_get_ptr(); + char *video_driver = settings->arrays.video_driver; + char *menu_driver = settings->arrays.menu_driver; + size_t menu_driver_len = strlen(menu_driver); + size_t video_driver_len = strlen(video_driver); - if (string_is_equal (menu_driver, "rgui") || - string_is_equal(menu_driver, "null") || - string_is_equal(video_driver, "null")) + if ( string_is_equal_memcmp_fast(menu_driver, "rgui", menu_driver_len) || + string_is_equal_memcmp_fast(menu_driver, "null", menu_driver_len) || + string_is_equal_memcmp_fast(video_driver, "null", video_driver_len)) return true; /* TODO/FIXME - maintenance hazard */ - if (string_is_equal(video_driver, "d3d9") || - string_is_equal(video_driver, "d3d10") || - string_is_equal(video_driver, "d3d11") || - string_is_equal(video_driver, "d3d12") || - string_is_equal(video_driver, "gdi") || - string_is_equal(video_driver, "gl") || - string_is_equal(video_driver, "gl1") || - string_is_equal(video_driver, "gx2") || - string_is_equal(video_driver, "vulkan") || - string_is_equal(video_driver, "glcore") || - string_is_equal(video_driver, "metal") || - string_is_equal(video_driver, "ctr") || - string_is_equal(video_driver, "vita2d")) + if ( string_is_equal_memcmp_fast(video_driver, "d3d9", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "d3d10", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "d3d11", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "d3d12", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "gdi", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "gl", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "gl1", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "gx2", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "vulkan", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "glcore", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "metal", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "ctr", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "vita2d", video_driver_len)) return true; return false; @@ -2569,22 +2571,24 @@ static bool check_menu_driver_compatibility(void) static bool check_shader_compatibility(enum file_path_enum enum_idx) { settings_t *settings = config_get_ptr(); + char *video_driver = settings->arrays.video_driver; + size_t video_driver_len = strlen(video_driver); - if (string_is_equal(settings->arrays.video_driver, "vulkan") || - string_is_equal(settings->arrays.video_driver, "metal") || - string_is_equal(settings->arrays.video_driver, "glcore") || - string_is_equal(settings->arrays.video_driver, "d3d11") || - string_is_equal(settings->arrays.video_driver, "d3d12") || - string_is_equal(settings->arrays.video_driver, "gx2")) + if (string_is_equal_memcmp_fast(video_driver, "vulkan", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "metal", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "glcore", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "d3d11", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "d3d12", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "gx2", video_driver_len)) { if (enum_idx != FILE_PATH_SLANGP_EXTENSION) return false; return true; } - if (string_is_equal(settings->arrays.video_driver, "gl") || - string_is_equal(settings->arrays.video_driver, "d3d8") || - string_is_equal(settings->arrays.video_driver, "d3d9") + if (string_is_equal_memcmp_fast(video_driver, "gl", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "d3d8", video_driver_len) || + string_is_equal_memcmp_fast(video_driver, "d3d9", video_driver_len) ) { if (enum_idx == FILE_PATH_SLANGP_EXTENSION) diff --git a/database_info.c b/database_info.c index b723b79283..6cda69588c 100644 --- a/database_info.c +++ b/database_info.c @@ -170,6 +170,7 @@ static int database_cursor_iterate(libretrodb_cursor_t *cur, for (i = 0; i < item.val.map.len; i++) { + size_t str_len; struct rmsgpack_dom_value *key = &item.val.map.items[i].key; struct rmsgpack_dom_value *val = &item.val.map.items[i].value; const char *val_string = NULL; @@ -179,116 +180,117 @@ static int database_cursor_iterate(libretrodb_cursor_t *cur, val_string = val->val.string.buff; str = key->val.string.buff; + str_len = strlen(str); - if (string_is_equal(str, "publisher")) + if (string_is_equal_memcmp_fast(str, "publisher", str_len)) { if (!string_is_empty(val_string)) db_info->publisher = strdup(val_string); } - else if (string_is_equal(str, "developer")) + else if (string_is_equal_memcmp_fast(str, "developer", str_len)) { if (!string_is_empty(val_string)) db_info->developer = string_split(val_string, "|"); } - else if (string_is_equal(str, "serial")) + else if (string_is_equal_memcmp_fast(str, "serial", str_len)) { if (!string_is_empty(val_string)) db_info->serial = strdup(val_string); } - else if (string_is_equal(str, "rom_name")) + else if (string_is_equal_memcmp_fast(str, "rom_name", str_len)) { if (!string_is_empty(val_string)) db_info->rom_name = strdup(val_string); } - else if (string_is_equal(str, "name")) + else if (string_is_equal_memcmp_fast(str, "name", str_len)) { if (!string_is_empty(val_string)) db_info->name = strdup(val_string); } - else if (string_is_equal(str, "description")) + else if (string_is_equal_memcmp_fast(str, "description", str_len)) { if (!string_is_empty(val_string)) db_info->description = strdup(val_string); } - else if (string_is_equal(str, "genre")) + else if (string_is_equal_memcmp_fast(str, "genre", str_len)) { if (!string_is_empty(val_string)) db_info->genre = strdup(val_string); } - else if (string_is_equal(str, "origin")) + else if (string_is_equal_memcmp_fast(str, "origin", str_len)) { if (!string_is_empty(val_string)) db_info->origin = strdup(val_string); } - else if (string_is_equal(str, "franchise")) + else if (string_is_equal_memcmp_fast(str, "franchise", str_len)) { if (!string_is_empty(val_string)) db_info->franchise = strdup(val_string); } - else if (string_is_equal(str, "bbfc_rating")) + else if (string_is_equal_memcmp_fast(str, "bbfc_rating", str_len)) { if (!string_is_empty(val_string)) db_info->bbfc_rating = strdup(val_string); } - else if (string_is_equal(str, "esrb_rating")) + else if (string_is_equal_memcmp_fast(str, "esrb_rating", str_len)) { if (!string_is_empty(val_string)) db_info->esrb_rating = strdup(val_string); } - else if (string_is_equal(str, "elspa_rating")) + else if (string_is_equal_memcmp_fast(str, "elspa_rating", str_len)) { if (!string_is_empty(val_string)) db_info->elspa_rating = strdup(val_string); } - else if (string_is_equal(str, "cero_rating")) + else if (string_is_equal_memcmp_fast(str, "cero_rating", str_len)) { if (!string_is_empty(val_string)) db_info->cero_rating = strdup(val_string); } - else if (string_is_equal(str, "pegi_rating")) + else if (string_is_equal_memcmp_fast(str, "pegi_rating", str_len)) { if (!string_is_empty(val_string)) db_info->pegi_rating = strdup(val_string); } - else if (string_is_equal(str, "enhancement_hw")) + else if (string_is_equal_memcmp_fast(str, "enhancement_hw", str_len)) { if (!string_is_empty(val_string)) db_info->enhancement_hw = strdup(val_string); } - else if (string_is_equal(str, "edge_review")) + else if (string_is_equal_memcmp_fast(str, "edge_review", str_len)) { if (!string_is_empty(val_string)) db_info->edge_magazine_review = strdup(val_string); } - else if (string_is_equal(str, "edge_rating")) + else if (string_is_equal_memcmp_fast(str, "edge_rating", str_len)) db_info->edge_magazine_rating = (unsigned)val->val.uint_; - else if (string_is_equal(str, "edge_issue")) + else if (string_is_equal_memcmp_fast(str, "edge_issue", str_len)) db_info->edge_magazine_issue = (unsigned)val->val.uint_; - else if (string_is_equal(str, "famitsu_rating")) + else if (string_is_equal_memcmp_fast(str, "famitsu_rating", str_len)) db_info->famitsu_magazine_rating = (unsigned)val->val.uint_; - else if (string_is_equal(str, "tgdb_rating")) + else if (string_is_equal_memcmp_fast(str, "tgdb_rating", str_len)) db_info->tgdb_rating = (unsigned)val->val.uint_; - else if (string_is_equal(str, "users")) + else if (string_is_equal_memcmp_fast(str, "users", str_len)) db_info->max_users = (unsigned)val->val.uint_; - else if (string_is_equal(str, "releasemonth")) + else if (string_is_equal_memcmp_fast(str, "releasemonth", str_len)) db_info->releasemonth = (unsigned)val->val.uint_; - else if (string_is_equal(str, "releaseyear")) + else if (string_is_equal_memcmp_fast(str, "releaseyear", str_len)) db_info->releaseyear = (unsigned)val->val.uint_; - else if (string_is_equal(str, "rumble")) + else if (string_is_equal_memcmp_fast(str, "rumble", str_len)) db_info->rumble_supported = (int)val->val.uint_; - else if (string_is_equal(str, "coop")) + else if (string_is_equal_memcmp_fast(str, "coop", str_len)) db_info->coop_supported = (int)val->val.uint_; - else if (string_is_equal(str, "analog")) + else if (string_is_equal_memcmp_fast(str, "analog", str_len)) db_info->analog_supported = (int)val->val.uint_; - else if (string_is_equal(str, "size")) + else if (string_is_equal_memcmp_fast(str, "size", str_len)) db_info->size = (unsigned)val->val.uint_; - else if (string_is_equal(str, "crc")) + else if (string_is_equal_memcmp_fast(str, "crc", str_len)) db_info->crc32 = swap_if_little32( *(uint32_t*)val->val.binary.buff); - else if (string_is_equal(str, "sha1")) + else if (string_is_equal_memcmp_fast(str, "sha1", str_len)) db_info->sha1 = bin_to_hex_alloc( (uint8_t*)val->val.binary.buff, val->val.binary.len); - else if (string_is_equal(str, "md5")) + else if (string_is_equal_memcmp_fast(str, "md5", str_len)) db_info->md5 = bin_to_hex_alloc( (uint8_t*)val->val.binary.buff, val->val.binary.len); else diff --git a/gfx/drivers_shader/glslang_util.cpp b/gfx/drivers_shader/glslang_util.cpp index 9d5c7d046e..8d818c8c64 100644 --- a/gfx/drivers_shader/glslang_util.cpp +++ b/gfx/drivers_shader/glslang_util.cpp @@ -243,8 +243,9 @@ const char *glslang_format_to_string(enum glslang_format fmt) static glslang_format glslang_find_format(const char *fmt) { + size_t fmt_len = strlen(fmt); #undef FMT -#define FMT(x) if (string_is_equal(fmt, #x)) return SLANG_FORMAT_ ## x +#define FMT(x) if (string_is_equal_memcmp_fast(fmt, #x, fmt_len)) return SLANG_FORMAT_ ## x FMT(R8_UNORM); FMT(R8_UINT); FMT(R8_SINT); diff --git a/gfx/video_driver.c b/gfx/video_driver.c index fd2069696f..58096c50ae 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -3326,27 +3326,29 @@ enum gfx_ctx_api video_context_driver_get_api(void) if (ctx_api == GFX_CTX_NONE) { const char *video_driver = video_driver_get_ident(); - if (string_is_equal(video_driver, "d3d9")) + size_t video_driver_len = strlen(video_driver); + + if (string_is_equal_memcmp_fast(video_driver, "d3d9", video_driver_len)) return GFX_CTX_DIRECT3D9_API; - else if (string_is_equal(video_driver, "d3d10")) + else if (string_is_equal_memcmp_fast(video_driver, "d3d10", video_driver_len)) return GFX_CTX_DIRECT3D10_API; - else if (string_is_equal(video_driver, "d3d11")) + else if (string_is_equal_memcmp_fast(video_driver, "d3d11", video_driver_len)) return GFX_CTX_DIRECT3D11_API; - else if (string_is_equal(video_driver, "d3d12")) + else if (string_is_equal_memcmp_fast(video_driver, "d3d12", video_driver_len)) return GFX_CTX_DIRECT3D12_API; - else if (string_is_equal(video_driver, "gx2")) + else if (string_is_equal_memcmp_fast(video_driver, "gx2", video_driver_len)) return GFX_CTX_GX2_API; - else if (string_is_equal(video_driver, "gx")) + else if (string_is_equal_memcmp_fast(video_driver, "gx", video_driver_len)) return GFX_CTX_GX_API; - else if (string_is_equal(video_driver, "gl")) + else if (string_is_equal_memcmp_fast(video_driver, "gl", video_driver_len)) return GFX_CTX_OPENGL_API; - else if (string_is_equal(video_driver, "gl1")) + else if (string_is_equal_memcmp_fast(video_driver, "gl1", video_driver_len)) return GFX_CTX_OPENGL_API; - else if (string_is_equal(video_driver, "glcore")) + else if (string_is_equal_memcmp_fast(video_driver, "glcore", video_driver_len)) return GFX_CTX_OPENGL_API; - else if (string_is_equal(video_driver, "vulkan")) + else if (string_is_equal_memcmp_fast(video_driver, "vulkan", video_driver_len)) return GFX_CTX_VULKAN_API; - else if (string_is_equal(video_driver, "metal")) + else if (string_is_equal_memcmp_fast(video_driver, "metal", video_driver_len)) return GFX_CTX_METAL_API; return GFX_CTX_NONE; diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 75c8d4276c..f17a65b3c8 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -82,13 +82,14 @@ static const char *wrap_mode_to_str(enum gfx_wrap_type type) **/ static enum gfx_wrap_type wrap_str_to_mode(const char *wrap_mode) { - if (string_is_equal(wrap_mode, "clamp_to_border")) + size_t wrap_mode_len = strlen(wrap_mode); + if (string_is_equal_memcmp_fast(wrap_mode, "clamp_to_border", wrap_mode_len)) return RARCH_WRAP_BORDER; - else if (string_is_equal(wrap_mode, "clamp_to_edge")) + else if (string_is_equal_memcmp_fast(wrap_mode, "clamp_to_edge", wrap_mode_len)) return RARCH_WRAP_EDGE; - else if (string_is_equal(wrap_mode, "repeat")) + else if (string_is_equal_memcmp_fast(wrap_mode, "repeat", wrap_mode_len)) return RARCH_WRAP_REPEAT; - else if (string_is_equal(wrap_mode, "mirrored_repeat")) + else if (string_is_equal_memcmp_fast(wrap_mode, "mirrored_repeat", wrap_mode_len)) return RARCH_WRAP_MIRRORED_REPEAT; RARCH_WARN("Invalid wrapping type %s. Valid ones are: clamp_to_border" @@ -229,11 +230,15 @@ static bool video_shader_parse_pass(config_file_t *conf, if (*scale_type_x) { - if (string_is_equal(scale_type_x, "source")) + size_t scale_type_x_len = strlen(scale_type_x); + if (string_is_equal_memcmp_fast( + scale_type_x, "source", scale_type_x_len)) scale->type_x = RARCH_SCALE_INPUT; - else if (string_is_equal(scale_type_x, "viewport")) + else if (string_is_equal_memcmp_fast( + scale_type_x, "viewport", scale_type_x_len)) scale->type_x = RARCH_SCALE_VIEWPORT; - else if (string_is_equal(scale_type_x, "absolute")) + else if (string_is_equal_memcmp_fast( + scale_type_x, "absolute", scale_type_x_len)) scale->type_x = RARCH_SCALE_ABSOLUTE; else { @@ -244,11 +249,12 @@ static bool video_shader_parse_pass(config_file_t *conf, if (*scale_type_y) { - if (string_is_equal(scale_type_y, "source")) + size_t scale_type_y_len = strlen(scale_type_y); + if (string_is_equal_memcmp_fast(scale_type_y, "source", scale_type_y_len)) scale->type_y = RARCH_SCALE_INPUT; - else if (string_is_equal(scale_type_y, "viewport")) + else if (string_is_equal_memcmp_fast(scale_type_y, "viewport", scale_type_y_len)) scale->type_y = RARCH_SCALE_VIEWPORT; - else if (string_is_equal(scale_type_y, "absolute")) + else if (string_is_equal_memcmp_fast(scale_type_y, "absolute", scale_type_y_len)) scale->type_y = RARCH_SCALE_ABSOLUTE; else { @@ -612,6 +618,7 @@ static bool video_shader_parse_imports(config_file_t *conf, char mask_buf[64]; char equal_buf[64]; char semantic[64]; + size_t semantic_len = 0; unsigned addr = 0; unsigned mask = 0; unsigned equal = 0; @@ -636,17 +643,19 @@ static bool video_shader_parse_imports(config_file_t *conf, snprintf(mask_buf, sizeof(mask_buf), "%s_mask", id); snprintf(equal_buf, sizeof(equal_buf), "%s_equal", id); - if (string_is_equal(semantic, "capture")) + semantic_len = strlen(semantic); + + if (string_is_equal_memcmp_fast(semantic, "capture", semantic_len)) var->type = RARCH_STATE_CAPTURE; - else if (string_is_equal(semantic, "transition")) + else if (string_is_equal_memcmp_fast(semantic, "transition", semantic_len)) var->type = RARCH_STATE_TRANSITION; - else if (string_is_equal(semantic, "transition_count")) + else if (string_is_equal_memcmp_fast(semantic, "transition_count", semantic_len)) var->type = RARCH_STATE_TRANSITION_COUNT; - else if (string_is_equal(semantic, "capture_previous")) + else if (string_is_equal_memcmp_fast(semantic, "capture_previous", semantic_len)) var->type = RARCH_STATE_CAPTURE_PREV; - else if (string_is_equal(semantic, "transition_previous")) + else if (string_is_equal_memcmp_fast(semantic, "transition_previous", semantic_len)) var->type = RARCH_STATE_TRANSITION_PREV; - else if (string_is_equal(semantic, "python")) + else if (string_is_equal_memcmp_fast(semantic, "python", semantic_len)) var->type = RARCH_STATE_PYTHON; else { diff --git a/input/input_driver.c b/input/input_driver.c index 329d1a99d7..a12c305d21 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -2428,14 +2428,17 @@ static void parse_hat(struct retro_keybind *bind, const char *str) return; } - if (string_is_equal(dir, "up")) - hat_dir = HAT_UP_MASK; - else if (string_is_equal(dir, "down")) - hat_dir = HAT_DOWN_MASK; - else if (string_is_equal(dir, "left")) - hat_dir = HAT_LEFT_MASK; - else if (string_is_equal(dir, "right")) - hat_dir = HAT_RIGHT_MASK; + { + size_t dir_size = strlen(dir); + if (string_is_equal_memcmp_fast(dir, "up", dir_size)) + hat_dir = HAT_UP_MASK; + else if (string_is_equal_memcmp_fast(dir, "down", dir_size)) + hat_dir = HAT_DOWN_MASK; + else if (string_is_equal_memcmp_fast(dir, "left", dir_size)) + hat_dir = HAT_LEFT_MASK; + else if (string_is_equal_memcmp_fast(dir, "right", dir_size)) + hat_dir = HAT_RIGHT_MASK; + } if (hat_dir) bind->joykey = HAT_MAP(hat, hat_dir); diff --git a/intl/msg_hash_us.c b/intl/msg_hash_us.c index f0b6552d68..37c8b4dbb4 100644 --- a/intl/msg_hash_us.c +++ b/intl/msg_hash_us.c @@ -823,7 +823,7 @@ int menu_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len) snprintf(s, len, "Current Video driver."); - if (string_is_equal(settings->arrays.video_driver, "gl")) + if (string_is_equal_memcmp(settings->arrays.video_driver, "gl")) { snprintf(s, len, "OpenGL Video driver. \n" diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 7aeaf2cb29..3781f98fd0 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -824,13 +824,16 @@ bool config_get_bool(config_file_t *conf, const char *key, bool *in) if (entry) { - if (string_is_equal(entry->value, "true")) + size_t entry_len = strlen(entry->value); + const char *entry_val = entry->value; + + if (string_is_equal_memcmp_fast(entry_val, "true", entry_len)) *in = true; - else if (string_is_equal(entry->value, "1")) + else if (string_is_equal_memcmp_fast(entry_val, "1", entry_len)) *in = true; - else if (string_is_equal(entry->value, "false")) + else if (string_is_equal_memcmp_fast(entry_val, "false", entry_len)) *in = false; - else if (string_is_equal(entry->value, "0")) + else if (string_is_equal_memcmp_fast(entry_val, "0", entry_len)) *in = false; else return false; diff --git a/libretro-common/include/string/stdstring.h b/libretro-common/include/string/stdstring.h index 7ddaa1ac14..b8ca44bfcd 100644 --- a/libretro-common/include/string/stdstring.h +++ b/libretro-common/include/string/stdstring.h @@ -31,6 +31,7 @@ #include #include +#include #include RETRO_BEGIN_DECLS @@ -61,6 +62,18 @@ static INLINE bool string_is_equal(const char *a, const char *b) #define string_is_not_equal_fast(a, b, size) (memcmp(a, b, size) != 0) #define string_is_equal_fast(a, b, size) (memcmp(a, b, size) == 0) +#define string_is_equal_memcmp(a, b) (memcmp(a, b, MIN(strlen(a), (STRLEN_CONST(b)+1))) == 0) +/* Faster version of string_is_equal_memcmp - + * this version is intended to be used when you're + * going to be making repeated calls to this macro + * while a stays the same, thereby sparing you the + * overhead of the macro implicitly calling strlen + * per invocation + * + * Parameter explanation: + * c = size of a + */ +#define string_is_equal_memcmp_fast(a, b, c) (memcmp(a, b, MIN(c, (STRLEN_CONST(b)+1))) == 0) static INLINE void string_add_between_pairs(char *s, const char *str, size_t size) diff --git a/menu/drivers/menu_generic.c b/menu/drivers/menu_generic.c index 64fbc3091a..260ee3b30e 100644 --- a/menu/drivers/menu_generic.c +++ b/menu/drivers/menu_generic.c @@ -31,24 +31,25 @@ static enum action_iterate_type action_iterate_type(const char *label) { - if (string_is_equal(label, "info_screen")) + size_t label_len = strlen(label); + if (string_is_equal_memcmp_fast(label, "info_screen", label_len)) return ITERATE_TYPE_INFO; if ( - string_is_equal(label, "help") || - string_is_equal(label, "help_controls") || - string_is_equal(label, "help_what_is_a_core") || - string_is_equal(label, "help_loading_content") || - string_is_equal(label, "help_scanning_content") || - string_is_equal(label, "help_change_virtual_gamepad") || - string_is_equal(label, "help_audio_video_troubleshooting") || - string_is_equal(label, "help_send_debug_info") || - string_is_equal(label, "cheevos_description") + string_is_equal_memcmp_fast(label, "help", label_len) || + string_is_equal_memcmp_fast(label, "help_controls", label_len) || + string_is_equal_memcmp_fast(label, "help_what_is_a_core", label_len) || + string_is_equal_memcmp_fast(label, "help_loading_content", label_len) || + string_is_equal_memcmp_fast(label, "help_scanning_content", label_len) || + string_is_equal_memcmp_fast(label, "help_change_virtual_gamepad", label_len) || + string_is_equal_memcmp_fast(label, "help_audio_video_troubleshooting", label_len) || + string_is_equal_memcmp_fast(label, "help_send_debug_info", label_len) || + string_is_equal_memcmp_fast(label, "cheevos_description", label_len) ) return ITERATE_TYPE_HELP; if ( - string_is_equal(label, "custom_bind") || - string_is_equal(label, "custom_bind_all") || - string_is_equal(label, "custom_bind_defaults") + string_is_equal_memcmp_fast(label, "custom_bind", label_len) || + string_is_equal_memcmp_fast(label, "custom_bind_all", label_len) || + string_is_equal_memcmp_fast(label, "custom_bind_defaults", label_len) ) return ITERATE_TYPE_BIND; diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 15d4b94afe..e7d0c44776 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -962,10 +962,11 @@ static void xmb_update_savestate_thumbnail_path(void *data, unsigned i) if (!string_is_empty(entry.label)) { + size_t entry_label_len = strlen(entry.label); if ( (settings->bools.savestate_thumbnail_enable) - && ((string_is_equal(entry.label, "state_slot")) - || (string_is_equal(entry.label, "loadstate")) - || (string_is_equal(entry.label, "savestate")))) + && ( (string_is_equal_memcmp_fast(entry.label, "state_slot", entry_label_len)) + || (string_is_equal_memcmp_fast(entry.label, "loadstate" , entry_label_len)) + || (string_is_equal_memcmp_fast(entry.label, "savestate" , entry_label_len)))) { size_t path_size = 8204 * sizeof(char); char *path = (char*)malloc(path_size); @@ -2106,8 +2107,8 @@ static void xmb_populate_entries(void *data, const char *path, const char *label, unsigned k) { - xmb_handle_t *xmb = (xmb_handle_t*)data; unsigned xmb_system_tab; + xmb_handle_t *xmb = (xmb_handle_t*)data; if (!xmb) return; @@ -2737,7 +2738,7 @@ static int xmb_draw_item( else if (string_is_equal(entry->value, msg_hash_to_str(MENU_ENUM_LABEL_ENABLED)) || (string_is_equal(entry->value, - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ON)))) + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ON)))) { if (xmb->textures.list[XMB_TEXTURE_SWITCH_ON]) texture_switch = xmb->textures.list[XMB_TEXTURE_SWITCH_ON]; @@ -2748,23 +2749,22 @@ static int xmb_draw_item( { if (!string_is_empty(entry->value)) { + size_t entry_val_len = strlen(entry->value); if ( - string_is_equal(entry->value, "...") || - string_is_equal(entry->value, "(PRESET)") || - string_is_equal(entry->value, "(SHADER)") || - string_is_equal(entry->value, "(COMP)") || - string_is_equal(entry->value, "(CORE)") || - string_is_equal(entry->value, "(MOVIE)") || - string_is_equal(entry->value, "(MUSIC)") || - string_is_equal(entry->value, "(DIR)") || - string_is_equal(entry->value, "(RDB)") || - string_is_equal(entry->value, "(CURSOR)")|| - string_is_equal(entry->value, "(CFILE)") || - string_is_equal(entry->value, "(FILE)") || - string_is_equal(entry->value, "(IMAGE)") - ) - { - } + string_is_equal_memcmp_fast(entry->value, "...", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(PRESET)", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(SHADER)", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(COMP)", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(CORE)", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(MOVIE)", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(MUSIC)", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(DIR)", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(RDB)", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(CURSOR)", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(CFILE)", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(FILE)", entry_val_len) || + string_is_equal_memcmp_fast(entry->value, "(IMAGE)", entry_val_len) + ) { } else do_draw_text = true; } diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 8420fbc327..d757b0ea3e 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1088,11 +1088,12 @@ static int create_string_list_rdb_entry_int( static enum msg_file_type extension_to_file_hash_type(const char *ext) { - if (string_is_equal(ext, "sha1")) + size_t ext_len = strlen(ext); + if (string_is_equal_memcmp_fast(ext, "sha1", ext_len)) return FILE_TYPE_SHA1; - else if (string_is_equal(ext, "crc")) + else if (string_is_equal_memcmp_fast(ext, "crc", ext_len)) return FILE_TYPE_CRC; - else if (string_is_equal(ext, "md5")) + else if (string_is_equal_memcmp_fast(ext, "md5", ext_len)) return FILE_TYPE_MD5; return FILE_TYPE_NONE; } @@ -1190,21 +1191,25 @@ static int menu_displaylist_parse_database_entry(menu_handle_t *menu, { if (tmp_str_list->size > 1) { - const char *elem0 = tmp_str_list->elems[0].data; - const char *elem1 = tmp_str_list->elems[1].data; + const char *elem0 = tmp_str_list->elems[0].data; + const char *elem1 = tmp_str_list->elems[1].data; + size_t crc_str_len = strlen(crc_str); switch (extension_to_file_hash_type(elem1)) { case FILE_TYPE_CRC: - if (string_is_equal(crc_str, elem0)) + if (string_is_equal_memcmp_fast(crc_str, elem0, + crc_str_len)) match_found = true; break; case FILE_TYPE_SHA1: - if (string_is_equal(db_info_entry->sha1, elem0)) + if (string_is_equal_memcmp_fast(db_info_entry->sha1, + elem0, crc_str_len)) match_found = true; break; case FILE_TYPE_MD5: - if (string_is_equal(db_info_entry->md5, elem0)) + if (string_is_equal_memcmp_fast(db_info_entry->md5, + elem0, crc_str_len)) match_found = true; break; default: @@ -2387,7 +2392,8 @@ static unsigned menu_displaylist_parse_cores( return items_found; } - if (string_is_equal(info->label, msg_hash_to_str(MENU_ENUM_LABEL_CORE_LIST))) + if (string_is_equal(info->label, + msg_hash_to_str(MENU_ENUM_LABEL_CORE_LIST))) info->download_core = true; dir_list_sort(str_list, true); @@ -2465,7 +2471,8 @@ static unsigned menu_displaylist_parse_cores( else { file_type = FILE_TYPE_CORE; - if (string_is_equal(info->label, msg_hash_to_str(MENU_ENUM_LABEL_SIDELOAD_CORE_LIST))) + if (string_is_equal(info->label, + msg_hash_to_str(MENU_ENUM_LABEL_SIDELOAD_CORE_LIST))) enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_SIDELOAD_CORE; else enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_CORE; diff --git a/playlist.c b/playlist.c index 123aef2063..b275cfc324 100644 --- a/playlist.c +++ b/playlist.c @@ -1299,9 +1299,7 @@ static JSON_Parser_HandlerResult JSONEndArrayHandler(JSON_Parser parser) else if (pCtx->object_depth == 2) { if (pCtx->in_subsystem_roms && string_is_equal(pCtx->current_items_string, "subsystem_roms") && pCtx->array_depth == 1) - { pCtx->in_subsystem_roms = false; - } } return JSON_Parser_Continue; @@ -1455,50 +1453,48 @@ static JSON_Parser_HandlerResult JSONObjectMemberHandler(JSON_Parser parser, cha return JSON_Parser_Abort; } - if (length) + if (length && !string_is_empty(pValue)) { - if (!string_is_empty(pValue)) - { - if (!string_is_empty(pCtx->current_items_string)) - free(pCtx->current_items_string); - pCtx->current_items_string = strdup(pValue); - } + size_t pvalue_len = strlen(pValue); + if (!string_is_empty(pCtx->current_items_string)) + free(pCtx->current_items_string); + pCtx->current_items_string = strdup(pValue); - if (string_is_equal(pValue, "path")) + if (string_is_equal_memcmp_fast(pValue, "path", pvalue_len)) pCtx->current_entry_val = &pCtx->current_entry->path; - else if (string_is_equal(pValue, "label")) + else if (string_is_equal_memcmp_fast(pValue, "label", pvalue_len)) pCtx->current_entry_val = &pCtx->current_entry->label; - else if (string_is_equal(pValue, "core_path")) + else if (string_is_equal_memcmp_fast(pValue, "core_path", pvalue_len)) pCtx->current_entry_val = &pCtx->current_entry->core_path; - else if (string_is_equal(pValue, "core_name")) + else if (string_is_equal_memcmp_fast(pValue, "core_name", pvalue_len)) pCtx->current_entry_val = &pCtx->current_entry->core_name; - else if (string_is_equal(pValue, "crc32")) + else if (string_is_equal_memcmp_fast(pValue, "crc32", pvalue_len)) pCtx->current_entry_val = &pCtx->current_entry->crc32; - else if (string_is_equal(pValue, "db_name")) + else if (string_is_equal_memcmp_fast(pValue, "db_name", pvalue_len)) pCtx->current_entry_val = &pCtx->current_entry->db_name; - else if (string_is_equal(pValue, "subsystem_ident")) + else if (string_is_equal_memcmp_fast(pValue, "subsystem_ident", pvalue_len)) pCtx->current_entry_val = &pCtx->current_entry->subsystem_ident; - else if (string_is_equal(pValue, "subsystem_name")) + else if (string_is_equal_memcmp_fast(pValue, "subsystem_name", pvalue_len)) pCtx->current_entry_val = &pCtx->current_entry->subsystem_name; - else if (string_is_equal(pValue, "subsystem_roms")) + else if (string_is_equal_memcmp_fast(pValue, "subsystem_roms", pvalue_len)) pCtx->current_entry_string_list_val = &pCtx->current_entry->subsystem_roms; - else if (string_is_equal(pValue, "runtime_hours")) + else if (string_is_equal_memcmp_fast(pValue, "runtime_hours", pvalue_len)) pCtx->current_entry_uint_val = &pCtx->current_entry->runtime_hours; - else if (string_is_equal(pValue, "runtime_minutes")) + else if (string_is_equal_memcmp_fast(pValue, "runtime_minutes", pvalue_len)) pCtx->current_entry_uint_val = &pCtx->current_entry->runtime_minutes; - else if (string_is_equal(pValue, "runtime_seconds")) + else if (string_is_equal_memcmp_fast(pValue, "runtime_seconds", pvalue_len)) pCtx->current_entry_uint_val = &pCtx->current_entry->runtime_seconds; - else if (string_is_equal(pValue, "last_played_year")) + else if (string_is_equal_memcmp_fast(pValue, "last_played_year", pvalue_len)) pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_year; - else if (string_is_equal(pValue, "last_played_month")) + else if (string_is_equal_memcmp_fast(pValue, "last_played_month", pvalue_len)) pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_month; - else if (string_is_equal(pValue, "last_played_day")) + else if (string_is_equal_memcmp_fast(pValue, "last_played_day", pvalue_len)) pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_day; - else if (string_is_equal(pValue, "last_played_hour")) + else if (string_is_equal_memcmp_fast(pValue, "last_played_hour", pvalue_len)) pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_hour; - else if (string_is_equal(pValue, "last_played_minute")) + else if (string_is_equal_memcmp_fast(pValue, "last_played_minute", pvalue_len)) pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_minute; - else if (string_is_equal(pValue, "last_played_second")) + else if (string_is_equal_memcmp_fast(pValue, "last_played_second", pvalue_len)) pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_second; else { diff --git a/retroarch.c b/retroarch.c index 39a0bbd372..eac3798b71 100644 --- a/retroarch.c +++ b/retroarch.c @@ -316,71 +316,72 @@ static char launch_arguments[4096]; static const void *find_driver_nonempty(const char *label, int i, char *s, size_t len) { - const void *drv = NULL; + const void *drv = NULL; + size_t label_len = strlen(label); - if (string_is_equal(label, "camera_driver")) + if (string_is_equal_memcmp_fast(label, "camera_driver", label_len)) { drv = camera_driver_find_handle(i); if (drv) strlcpy(s, camera_driver_find_ident(i), len); } - else if (string_is_equal(label, "location_driver")) + else if (string_is_equal_memcmp_fast(label, "location_driver", label_len)) { drv = location_driver_find_handle(i); if (drv) strlcpy(s, location_driver_find_ident(i), len); } #ifdef HAVE_MENU - else if (string_is_equal(label, "menu_driver")) + else if (string_is_equal_memcmp_fast(label, "menu_driver", label_len)) { drv = menu_driver_find_handle(i); if (drv) strlcpy(s, menu_driver_find_ident(i), len); } #endif - else if (string_is_equal(label, "input_driver")) + else if (string_is_equal_memcmp_fast(label, "input_driver", label_len)) { drv = input_driver_find_handle(i); if (drv) strlcpy(s, input_driver_find_ident(i), len); } - else if (string_is_equal(label, "input_joypad_driver")) + else if (string_is_equal_memcmp_fast(label, "input_joypad_driver", label_len)) { drv = joypad_driver_find_handle(i); if (drv) strlcpy(s, joypad_driver_find_ident(i), len); } - else if (string_is_equal(label, "video_driver")) + else if (string_is_equal_memcmp_fast(label, "video_driver", label_len)) { drv = video_driver_find_handle(i); if (drv) strlcpy(s, video_driver_find_ident(i), len); } - else if (string_is_equal(label, "audio_driver")) + else if (string_is_equal_memcmp_fast(label, "audio_driver", label_len)) { drv = audio_driver_find_handle(i); if (drv) strlcpy(s, audio_driver_find_ident(i), len); } - else if (string_is_equal(label, "record_driver")) + else if (string_is_equal_memcmp_fast(label, "record_driver", label_len)) { drv = record_driver_find_handle(i); if (drv) strlcpy(s, record_driver_find_ident(i), len); } - else if (string_is_equal(label, "midi_driver")) + else if (string_is_equal_memcmp_fast(label, "midi_driver", label_len)) { drv = midi_driver_find_handle(i); if (drv) strlcpy(s, midi_driver_find_ident(i), len); } - else if (string_is_equal(label, "audio_resampler_driver")) + else if (string_is_equal_memcmp_fast(label, "audio_resampler_driver", label_len)) { drv = audio_resampler_driver_find_handle(i); if (drv) strlcpy(s, audio_resampler_driver_find_ident(i), len); } - else if (string_is_equal(label, "wifi_driver")) + else if (string_is_equal_memcmp_fast(label, "wifi_driver", label_len)) { drv = wifi_driver_find_handle(i); if (drv) @@ -3735,7 +3736,7 @@ static enum runloop_state runloop_check_state( char *menu_driver = settings->arrays.menu_driver; bool pressed = BIT256_GET( current_input, RARCH_MENU_TOGGLE) && - !string_is_equal(menu_driver, "null"); + !string_is_equal_memcmp(menu_driver, "null"); if (menu_event_kb_is_set(RETROK_F1) == 1) { diff --git a/setting_list.c b/setting_list.c index 836a76708a..b193991cb1 100644 --- a/setting_list.c +++ b/setting_list.c @@ -203,21 +203,21 @@ static float recalc_step_based_on_length_of_action(rarch_setting_t *setting) float step = setting->step; #ifdef HAVE_MENU global_t *global = global_get_ptr(); - if ( global ) + if (global) { - if ( global->menu.action_press_time > _21_SECONDS) + if (global->menu.action_press_time > _21_SECONDS) step = setting->step*1000000.0f ; - else if ( global->menu.action_press_time > _18_SECONDS) + else if (global->menu.action_press_time > _18_SECONDS) step = setting->step*100000.0f ; - else if ( global->menu.action_press_time > _15_SECONDS) + else if (global->menu.action_press_time > _15_SECONDS) step = setting->step*10000.0f ; - else if ( global->menu.action_press_time > _12_SECONDS) + else if (global->menu.action_press_time > _12_SECONDS) step = setting->step*1000.0f ; - else if ( global->menu.action_press_time > _9_SECONDS) + else if (global->menu.action_press_time > _9_SECONDS) step = setting->step*100.0f ; - else if ( global->menu.action_press_time > _6_SECONDS) + else if (global->menu.action_press_time > _6_SECONDS) step = setting->step*10.0f ; - else if ( global->menu.action_press_time > _3_SECONDS) + else if (global->menu.action_press_time > _3_SECONDS) step = setting->step*5.0f ; else step = setting->step ; @@ -526,14 +526,17 @@ int setting_set_with_string_representation(rarch_setting_t* setting, case ST_STRING: case ST_STRING_OPTIONS: case ST_ACTION: - if ( setting->value.target.string != NULL) + if (setting->value.target.string != NULL) strlcpy(setting->value.target.string, value, setting->size); break; case ST_BOOL: - if (string_is_equal(value, "true")) - *setting->value.target.boolean = true; - else if (string_is_equal(value, "false")) - *setting->value.target.boolean = false; + { + size_t value_len = strlen(value); + if (string_is_equal_memcmp_fast(value, "true", value_len)) + *setting->value.target.boolean = true; + else if (string_is_equal_memcmp_fast(value, "false", value_len)) + *setting->value.target.boolean = false; + } break; default: break; diff --git a/tasks/task_database.c b/tasks/task_database.c index 8ade0e6cd3..46f6a1ce82 100644 --- a/tasks/task_database.c +++ b/tasks/task_database.c @@ -161,46 +161,48 @@ static int task_database_iterate_start(database_info_handle_t *db, static int intfstream_get_serial(intfstream_t *fd, char *serial) { - const char *system_name = NULL; + const char *system_name = NULL; + size_t system_name_len = 0; - /* Check if the system was not auto-detected. */ - if (detect_system(fd, &system_name) < 0) - { - /* Attempt to read an ASCII serial, like Wii. */ - if (detect_serial_ascii_game(fd, serial)) - { - /* ASCII serial (Wii) was detected. */ + /* Check if the system was not auto-detected. */ + if (detect_system(fd, &system_name) < 0) + { + /* Attempt to read an ASCII serial, like Wii. */ + if (detect_serial_ascii_game(fd, serial)) + { + /* ASCII serial (Wii) was detected. */ + RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial); + return 0; + } + + /* Any other non-system specific detection methods? */ + return 0; + } + + system_name_len = strlen(system_name); + + if (string_is_equal_memcmp_fast(system_name, "psp", system_name_len)) + { + if (detect_psp_game(fd, serial) == 0) + return 0; RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial); + } + else if (string_is_equal_memcmp_fast(system_name, "ps1", system_name_len)) + { + if (detect_ps1_game(fd, serial) == 0) + return 0; + RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial); + } + else if (string_is_equal_memcmp_fast(system_name, "gc", system_name_len)) + { + if (detect_gc_game(fd, serial) == 0) + return 0; + RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial); + } + else return 0; - } - /* Any other non-system specific detection methods? */ - return 0; - } - - if (string_is_equal(system_name, "psp")) - { - if (detect_psp_game(fd, serial) == 0) - return 0; - RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial); - } - else if (string_is_equal(system_name, "ps1")) - { - if (detect_ps1_game(fd, serial) == 0) - return 0; - RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial); - } - else if (string_is_equal(system_name, "gc")) - { - if (detect_gc_game(fd, serial) == 0) - return 0; - RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial); - } - else { - return 0; - } - - return 1; + return 1; } static bool intfstream_file_get_serial(const char *name, @@ -567,43 +569,44 @@ end: static enum msg_file_type extension_to_file_type(const char *ext) { + size_t ext_len = strlen(ext); if ( - string_is_equal(ext, "7z") || - string_is_equal(ext, "7Z") || - string_is_equal(ext, "zip") || - string_is_equal(ext, "ZIP") || - string_is_equal(ext, "apk") || - string_is_equal(ext, "APK") + string_is_equal_memcmp_fast(ext, "7z", ext_len) || + string_is_equal_memcmp_fast(ext, "7Z", ext_len) || + string_is_equal_memcmp_fast(ext, "zip", ext_len) || + string_is_equal_memcmp_fast(ext, "ZIP", ext_len) || + string_is_equal_memcmp_fast(ext, "apk", ext_len) || + string_is_equal_memcmp_fast(ext, "APK", ext_len) ) return FILE_TYPE_COMPRESSED; if ( - string_is_equal(ext, "cue") || - string_is_equal(ext, "CUE") + string_is_equal_memcmp_fast(ext, "cue", ext_len) || + string_is_equal_memcmp_fast(ext, "CUE", ext_len) ) return FILE_TYPE_CUE; if ( - string_is_equal(ext, "gdi") || - string_is_equal(ext, "GDI") + string_is_equal_memcmp_fast(ext, "gdi", ext_len) || + string_is_equal_memcmp_fast(ext, "GDI", ext_len) ) return FILE_TYPE_GDI; if ( - string_is_equal(ext, "iso") || - string_is_equal(ext, "ISO") + string_is_equal_memcmp_fast(ext, "iso", ext_len) || + string_is_equal_memcmp_fast(ext, "ISO", ext_len) ) return FILE_TYPE_ISO; if ( - string_is_equal(ext, "chd") || - string_is_equal(ext, "CHD") + string_is_equal_memcmp_fast(ext, "chd", ext_len) || + string_is_equal_memcmp_fast(ext, "CHD", ext_len) ) return FILE_TYPE_CHD; if ( - string_is_equal(ext, "wbfs") || - string_is_equal(ext, "WBFS") + string_is_equal_memcmp_fast(ext, "wbfs", ext_len) || + string_is_equal_memcmp_fast(ext, "WBFS", ext_len) ) return FILE_TYPE_WBFS; if ( - string_is_equal(ext, "lutro") || - string_is_equal(ext, "LUTRO") + string_is_equal_memcmp_fast(ext, "lutro", ext_len) || + string_is_equal_memcmp_fast(ext, "LUTRO", ext_len) ) return FILE_TYPE_LUTRO; return FILE_TYPE_NONE; diff --git a/tasks/task_database_cue.c b/tasks/task_database_cue.c index bcd19ec728..430557b1d7 100644 --- a/tasks/task_database_cue.c +++ b/tasks/task_database_cue.c @@ -249,44 +249,40 @@ int detect_psp_game(intfstream_t *fd, char *game_id) if (intfstream_read(fd, game_id, 5) > 0) { - game_id[5] = '\0'; + size_t game_id_size = strlen(game_id); + game_id[5] = '\0'; if ( - (string_is_equal(game_id, "ULES-")) - || (string_is_equal(game_id, "ULUS-")) - || (string_is_equal(game_id, "ULJS-")) + ( string_is_equal_memcmp_fast(game_id, "ULES-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "ULUS-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "ULJS-", game_id_size)) - || (string_is_equal(game_id, "ULEM-")) - || (string_is_equal(game_id, "ULUM-")) - || (string_is_equal(game_id, "ULJM-")) + || (string_is_equal_memcmp_fast(game_id, "ULEM-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "ULUM-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "ULJM-", game_id_size)) - || (string_is_equal(game_id, "UCES-")) - || (string_is_equal(game_id, "UCUS-")) - || (string_is_equal(game_id, "UCJS-")) - || (string_is_equal(game_id, "UCAS-")) + || (string_is_equal_memcmp_fast(game_id, "UCES-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "UCUS-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "UCJS-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "UCAS-", game_id_size)) - || (string_is_equal(game_id, "NPEH-")) - || (string_is_equal(game_id, "NPUH-")) - || (string_is_equal(game_id, "NPJH-")) + || (string_is_equal_memcmp_fast(game_id, "NPEH-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "NPUH-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "NPJH-", game_id_size)) - || (string_is_equal(game_id, "NPEG-")) - || (string_is_equal(game_id, "NPUG-")) - || (string_is_equal(game_id, "NPJG-")) - || (string_is_equal(game_id, "NPHG-")) + || (string_is_equal_memcmp_fast(game_id, "NPEG-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "NPUG-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "NPJG-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "NPHG-", game_id_size)) - || (string_is_equal(game_id, "NPEZ-")) - || (string_is_equal(game_id, "NPUZ-")) - || (string_is_equal(game_id, "NPJZ-")) + || (string_is_equal_memcmp_fast(game_id, "NPEZ-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "NPUZ-", game_id_size)) + || (string_is_equal_memcmp_fast(game_id, "NPJZ-", game_id_size)) ) { intfstream_seek(fd, pos, SEEK_SET); if (intfstream_read(fd, game_id, 10) > 0) { -#if 0 - game_id[4] = '-'; - game_id[8] = game_id[9]; - game_id[9] = game_id[10]; -#endif game_id[10] = '\0'; rv = true; } @@ -333,10 +329,10 @@ int detect_serial_ascii_game(intfstream_t *fd, char *game_id) game_id[15] = '\0'; numberOfAscii = 0; - /* When scanning WBFS files, "WBFS" is discovered as the first serial. Ignore it. */ - if (string_is_equal(game_id, "WBFS")) { + /* When scanning WBFS files, "WBFS" is + * discovered as the first serial. Ignore it. */ + if (string_is_equal_memcmp(game_id, "WBFS")) continue; - } /* Loop through until we run out of ASCII characters. */ for (i = 0; i < 15; i++) @@ -399,7 +395,7 @@ int detect_system(intfstream_t *fd, const char **system_name) { magic[8] = '\0'; if (!string_is_empty(magic) && - string_is_equal(magic, "PSP GAME")) + string_is_equal_memcmp(magic, "PSP GAME")) { *system_name = "psp\0"; rv = 0;