Start using string_is_equal_fast/string_is_not_equal_fast macros

instead of straight memcmp
This commit is contained in:
twinaphex 2017-05-16 03:20:39 +02:00
parent 98a79f2279
commit 8eca08c6ac
16 changed files with 64 additions and 60 deletions

View File

@ -202,7 +202,7 @@ bool driver_find_next(const char *label, char *s, size_t len)
{
int i = driver_find_index(label, s);
if (i >= 0 && (memcmp(s, "null", 4) != 0))
if (i >= 0 && string_is_not_equal_fast(s, "null", 4))
{
find_driver_nonempty(label, i + 1, s, len);
return true;

View File

@ -906,7 +906,7 @@ static bool dynamic_verify_hw_context(enum retro_hw_context_type type,
switch (type)
{
case RETRO_HW_CONTEXT_VULKAN:
if (memcmp(video_ident, "vulkan", 6) != 0)
if (string_is_not_equal_fast(video_ident, "vulkan", 6))
return false;
break;
case RETRO_HW_CONTEXT_OPENGLES2:
@ -914,7 +914,7 @@ static bool dynamic_verify_hw_context(enum retro_hw_context_type type,
case RETRO_HW_CONTEXT_OPENGLES_VERSION:
case RETRO_HW_CONTEXT_OPENGL:
case RETRO_HW_CONTEXT_OPENGL_CORE:
if (memcmp(video_ident, "gl", 2) != 0)
if (string_is_not_equal_fast(video_ident, "gl", 2))
return false;
break;
default:

View File

@ -293,13 +293,13 @@ static void parse_hat(struct retro_keybind *bind, const char *str)
return;
}
if (memcmp(dir, "up", 2) == 0)
if (string_is_equal_fast(dir, "up", 2))
hat_dir = HAT_UP_MASK;
else if (memcmp(dir, "down", 4) == 0)
else if (string_is_equal_fast(dir, "down", 4))
hat_dir = HAT_DOWN_MASK;
else if (memcmp(dir, "left", 4) == 0)
else if (string_is_equal_fast(dir, "left", 4))
hat_dir = HAT_LEFT_MASK;
else if (memcmp(dir, "right", 5) == 0)
else if (string_is_equal_fast(dir, "right", 5))
hat_dir = HAT_RIGHT_MASK;
if (hat_dir)

View File

@ -747,13 +747,13 @@ bool config_get_bool(config_file_t *conf, const char *key, bool *in)
if (entry)
{
if (memcmp(entry->value, "true", 4) == 0)
if (string_is_equal_fast(entry->value, "true", 4))
*in = true;
else if (memcmp(entry->value, "1", 1) == 0)
else if (string_is_equal_fast(entry->value, "1", 1))
*in = true;
else if (memcmp(entry->value, "false", 5) == 0)
else if (string_is_equal_fast(entry->value, "false", 5))
*in = false;
else if (memcmp(entry->value, "0", 1) == 0)
else if (string_is_equal_fast(entry->value, "0", 1))
*in = false;
else
return false;

View File

@ -33,6 +33,7 @@
#include <formats/image.h>
#include <formats/rpng.h>
#include <streams/trans_stream.h>
#include <string/stdstring.h>
#include "rpng_internal.h"
@ -152,7 +153,7 @@ static enum png_chunk_type png_chunk_type(const struct png_chunk *chunk)
for (i = 0; i < ARRAY_SIZE(chunk_map); i++)
{
if (memcmp(chunk->type, chunk_map[i].id, 4) == 0)
if (string_is_equal_fast(chunk->type, chunk_map[i].id, 4))
return chunk_map[i].type;
}
@ -1153,7 +1154,7 @@ bool rpng_start(rpng_t *rpng)
for (i = 0; i < 8; i++)
header[i] = rpng->buff_data[i];
if (memcmp(header, png_magic, sizeof(png_magic)) != 0)
if (string_is_not_equal_fast(header, png_magic, sizeof(png_magic)))
return false;
rpng->buff_data += 8;

View File

@ -48,6 +48,9 @@ static INLINE bool string_is_equal(const char *a, const char *b)
return (*(const unsigned char*)a - *(const unsigned char*)b) == 0;
}
#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)
static INLINE bool string_is_equal_noncase(const char *a, const char *b)
{
int result;

View File

@ -124,7 +124,7 @@ static int parse_dir_entry(const char *name, char *file_path,
if (!include_dirs && is_dir)
return 1;
if ((memcmp(name, ".", 1) == 0) || (memcmp(name, "..", 2) == 0))
if (string_is_equal_fast(name, ".", 1) || string_is_equal_fast(name, "..", 2))
return 1;
if (!is_dir && ext_list &&

View File

@ -273,18 +273,13 @@ static int libretrodb_find_index(libretrodb_t *db, const char *index_name,
return -1;
}
static int node_compare(const void *a, const void *b, void *ctx)
{
return memcmp(a, b, *(uint8_t *)ctx);
}
static int binsearch(const void *buff, const void *item,
uint64_t count, uint8_t field_size, uint64_t *offset)
{
int mid = (int)(count / 2);
int item_size = field_size + sizeof(uint64_t);
uint64_t *current = (uint64_t *)buff + (mid * item_size);
int rv = node_compare(current, item, &field_size);
int rv = memcmp(current, item, field_size);
if (rv == 0)
{
@ -458,6 +453,11 @@ static uint64_t libretrodb_tell(libretrodb_t *db)
return filestream_seek(db->fd, 0, SEEK_CUR);
}
static int node_compare(const void *a, const void *b, void *ctx)
{
return memcmp(a, b, *(uint8_t *)ctx);
}
int libretrodb_create_index(libretrodb_t *db,
const char *name, const char *field_name)
{

View File

@ -943,7 +943,7 @@ static void xmb_update_thumbnail_path(void *data, unsigned i)
playlist_get_index(playlist, i,
NULL, NULL, NULL, &core_name, NULL, NULL);
if (core_name && (memcmp(core_name, "imageviewer", 11) == 0))
if (core_name && string_is_equal_fast(core_name, "imageviewer", 11))
{
strlcpy(xmb->thumbnail_file_path, entry.label,
sizeof(xmb->thumbnail_file_path));
@ -1013,9 +1013,9 @@ static void xmb_update_savestate_thumbnail_path(void *data, unsigned i)
xmb->savestate_thumbnail_file_path[0] = '\0';
if ( (settings->bools.savestate_thumbnail_enable)
&& ((memcmp(entry.label, "state_slot", 10) == 0)
|| (memcmp(entry.label, "loadstate", 9) == 0)
|| (memcmp(entry.label, "savestate", 9) == 0)))
&& ((string_is_equal_fast(entry.label, "state_slot", 10))
|| (string_is_equal_fast(entry.label, "loadstate", 9))
|| (string_is_equal_fast(entry.label, "savestate", 9))))
{
char path[PATH_MAX_LENGTH];
global_t *global = global_get_ptr();
@ -2488,7 +2488,7 @@ static void xmb_render(void *data, bool is_idle)
static bool xmb_shader_pipeline_active(video_frame_info_t *video_info)
{
if (memcmp(menu_driver_ident(), "xmb", 3) != 0)
if (string_is_not_equal_fast(menu_driver_ident(), "xmb", 3))
return false;
if (video_info->menu_shader_pipeline == XMB_SHADER_PIPELINE_WALLPAPER)
return false;

View File

@ -126,35 +126,35 @@ static bool menu_display_check_compatibility(
case MENU_VIDEO_DRIVER_GENERIC:
return true;
case MENU_VIDEO_DRIVER_OPENGL:
if (memcmp(video_driver, "gl", 2) == 0)
if (string_is_equal_fast(video_driver, "gl", 2))
return true;
break;
case MENU_VIDEO_DRIVER_VULKAN:
if (memcmp(video_driver, "vulkan", 6) == 0)
if (string_is_equal_fast(video_driver, "vulkan", 6))
return true;
break;
case MENU_VIDEO_DRIVER_DIRECT3D:
if (memcmp(video_driver, "d3d", 3) == 0)
if (string_is_equal_fast(video_driver, "d3d", 3))
return true;
break;
case MENU_VIDEO_DRIVER_VITA2D:
if (memcmp(video_driver, "vita2d", 6) == 0)
if (string_is_equal_fast(video_driver, "vita2d", 6))
return true;
break;
case MENU_VIDEO_DRIVER_CTR:
if (memcmp(video_driver, "ctr", 3) == 0)
if (string_is_equal_fast(video_driver, "ctr", 3))
return true;
break;
case MENU_VIDEO_DRIVER_CACA:
if (memcmp(video_driver, "caca", 4) == 0)
if (string_is_equal_fast(video_driver, "caca", 4))
return true;
break;
case MENU_VIDEO_DRIVER_GDI:
if (memcmp(video_driver, "gdi", 3) == 0)
if (string_is_equal_fast(video_driver, "gdi", 3))
return true;
break;
case MENU_VIDEO_DRIVER_VGA:
if (memcmp(video_driver, "vga", 3) == 0)
if (string_is_equal_fast(video_driver, "vga", 3))
return true;
break;
}

View File

@ -289,7 +289,7 @@ static void print_buf_lines(file_list_t *list, char *buf,
if (!string_is_empty(last))
{
if (memcmp(last, "_libretro", 9) != 0)
if (string_is_not_equal_fast(last, "_libretro", 9))
*last = '\0';
}
@ -352,7 +352,7 @@ static int menu_displaylist_parse_netplay(
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_LAN_SCAN_SETTINGS),
MENU_ENUM_LABEL_NETPLAY_LAN_SCAN_SETTINGS, MENU_SETTING_GROUP, 0, 0);
if (memcmp(settings->arrays.menu_driver, "xmb", 3) != 0)
if (string_is_not_equal_fast(settings->arrays.menu_driver, "xmb", 3))
menu_entries_append_enum(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_TAB),
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_TAB),
@ -2760,7 +2760,7 @@ static int menu_displaylist_parse_horizontal_list(
playlist_qsort(playlist);
if (memcmp(lpl_basename, "content_history", 15) == 0)
if (string_is_equal_fast(lpl_basename, "content_history", 15))
is_historylist = true;
menu_displaylist_parse_playlist(info,
@ -5012,7 +5012,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
info->need_push = true;
break;
case DISPLAYLIST_WIFI_SETTINGS_LIST:
if (memcmp(settings->arrays.wifi_driver, "null", 4) == 0)
if (string_is_equal_fast(settings->arrays.wifi_driver, "null", 4))
menu_entries_append_enum(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_NETWORKS_FOUND),
msg_hash_to_str(MENU_ENUM_LABEL_NO_NETWORKS_FOUND),
@ -5632,7 +5632,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
MENU_ENUM_LABEL_LOGGING_SETTINGS, PARSE_ACTION, false);
ret = menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_FRAME_THROTTLE_SETTINGS, PARSE_ACTION, false);
if (memcmp(settings->arrays.record_driver, "null", 4) != 0)
if (string_is_not_equal_fast(settings->arrays.record_driver, "null", 4))
ret = menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_RECORDING_SETTINGS, PARSE_ACTION, false);
ret = menu_displaylist_parse_settings_enum(menu, info,

View File

@ -98,16 +98,16 @@ void menu_event_osk_append(int ptr)
menu_event_set_osk_idx(OSK_LOWERCASE_LATIN);
else if (string_is_equal(osk_grid[ptr],"\xe2\x8a\x95")) /* plus sign (next button) */
#else
if (memcmp(osk_grid[ptr], "Bksp", 4) == 0)
if (string_is_equal_fast(osk_grid[ptr], "Bksp", 4))
input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD);
else if (memcmp(osk_grid[ptr], "Enter", 5) == 0)
else if (string_is_equal_fast(osk_grid[ptr], "Enter", 5))
input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD);
else
if (memcmp(osk_grid[ptr], "Upper", 5) == 0)
if (string_is_equal_fast(osk_grid[ptr], "Upper", 5))
menu_event_set_osk_idx(OSK_UPPERCASE_LATIN);
else if (memcmp(osk_grid[ptr], "Lower", 5) == 0)
else if (string_is_equal_fast(osk_grid[ptr], "Lower", 5))
menu_event_set_osk_idx(OSK_LOWERCASE_LATIN);
else if (memcmp(osk_grid[ptr], "Next", 4) == 0)
else if (string_is_equal_fast(osk_grid[ptr], "Next", 4))
#endif
if (menu_event_get_osk_idx() < OSK_TYPE_LAST - 1)
menu_event_set_osk_idx((enum osk_type)(menu_event_get_osk_idx() + 1));

View File

@ -386,9 +386,9 @@ int setting_set_with_string_representation(rarch_setting_t* setting,
strlcpy(setting->value.target.string, value, setting->size);
break;
case ST_BOOL:
if (memcmp(value, "true", 4) == 0)
if (string_is_equal_fast(value, "true", 4))
*setting->value.target.boolean = true;
else if (memcmp(value, "false", 5) == 0)
else if (string_is_equal_fast(value, "false", 5))
*setting->value.target.boolean = false;
break;
default:

View File

@ -140,13 +140,13 @@ static int iso_get_serial(database_state_handle_t *db_state,
if (rv < 0)
return rv;
if (memcmp(system_name, "psp", 3) == 0)
if (string_is_equal_fast(system_name, "psp", 3))
{
if (detect_psp_game(name, serial) == 0)
return 0;
RARCH_LOG("%s '%s'\n", msg_hash_to_str(MSG_FOUND_DISK_LABEL), serial);
}
else if (memcmp(system_name, "ps1", 3) == 0)
else if (string_is_equal_fast(system_name, "ps1", 3))
{
if (detect_ps1_game(name, serial) == 0)
return 0;

View File

@ -278,9 +278,9 @@ int detect_psp_game(const char *track_path, char *game_id)
{
game_id[5] = '\0';
if (
(memcmp(game_id, "ULES-", 5) == 0)
|| (memcmp(game_id, "ULUS-", 5) == 0)
|| (memcmp(game_id, "ULJS-", 5) == 0)
(string_is_equal_fast(game_id, "ULES-", 5))
|| (string_is_equal_fast(game_id, "ULUS-", 5))
|| (string_is_equal_fast(game_id, "ULJS-", 5))
|| (memcmp(game_id, "ULEM-", 5) == 0)
|| (memcmp(game_id, "ULUM-", 5) == 0)
@ -354,7 +354,7 @@ int detect_system(const char *track_path, const char **system_name)
goto clean;
}
if (memcmp(MAGIC_NUMBERS[i].magic, magic, MAGIC_LEN) == 0)
if (string_is_equal_fast(MAGIC_NUMBERS[i].magic, magic, MAGIC_LEN))
{
*system_name = MAGIC_NUMBERS[i].system_name;
rv = 0;
@ -366,7 +366,7 @@ int detect_system(const char *track_path, const char **system_name)
if (filestream_read(fd, magic, 8) > 0)
{
magic[8] = '\0';
if (memcmp(magic, "PSP GAME", 8) == 0)
if (string_is_equal_fast(magic, "PSP GAME", 8))
{
*system_name = "psp\0";
rv = 0;
@ -403,7 +403,7 @@ int find_first_data_track(const char *cue_path,
while (get_token(fd, tmp_token, MAX_TOKEN_LEN) > 0)
{
if (memcmp(tmp_token, "FILE", 4) == 0)
if (string_is_equal_fast(tmp_token, "FILE", 4))
{
char cue_dir[PATH_MAX_LENGTH];
@ -415,13 +415,13 @@ int find_first_data_track(const char *cue_path,
fill_pathname_join(track_path, cue_dir, tmp_token, max_len);
}
else if (memcmp(tmp_token, "TRACK", 5) == 0)
else if (string_is_equal_fast(tmp_token, "TRACK", 5))
{
int m, s, f;
get_token(fd, tmp_token, MAX_TOKEN_LEN);
get_token(fd, tmp_token, MAX_TOKEN_LEN);
if (memcmp(tmp_token, "AUDIO", 5) == 0)
if (string_is_equal_fast(tmp_token, "AUDIO", 5))
continue;
find_token(fd, "INDEX");

View File

@ -61,7 +61,7 @@ static void netplay_crc_scan_callback(void *task_data,
#ifdef HAVE_MENU
if (!string_is_empty(state->core_path) && !string_is_empty(state->content_path) &&
memcmp(state->content_path, "N/A", 3) != 0)
string_is_not_equal_fast(state->content_path, "N/A", 3))
{
command_event(CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED, state->hostname);
task_push_load_content_with_new_core_from_menu(
@ -73,7 +73,7 @@ static void netplay_crc_scan_callback(void *task_data,
else
#endif
if (!string_is_empty(state->core_path) && !string_is_empty(state->content_path) &&
memcmp(state->content_path, "N/A", 3) == 0)
string_is_equal_fast(state->content_path, "N/A", 3))
{
content_ctx_info_t content_info = {0};
@ -115,11 +115,11 @@ static void task_netplay_crc_scan_handler(retro_task_t *task)
}
if (state->lpl_list->size == 0 &&
memcmp(state->content_path, "N/A", 3) != 0)
string_is_not_equal_fast(state->content_path, "N/A", 3))
goto no_playlists;
/* Core requires content */
if (memcmp(state->content_path, "N/A", 3) != 0)
if (string_is_not_equal_fast(state->content_path, "N/A", 3))
{
/* CRC matching */
if (!string_is_equal(state->content_crc, "00000000|crc"))
@ -289,7 +289,7 @@ bool task_push_netplay_crc_scan(uint32_t crc, char* name,
{
strlcpy(state->core_path, info->list[i].path, sizeof(state->core_path));
if ((memcmp(state->content_path, "N/A", 3) != 0) &&
if (string_is_not_equal_fast(state->content_path, "N/A", 3) &&
!string_is_empty(info->list[i].supported_extensions))
{
strlcpy(state->core_extensions,