From ca0a8b2a116f577fd5b569329ecd2038cc04217a Mon Sep 17 00:00:00 2001 From: Otavio Pontes Date: Tue, 16 Jul 2019 21:06:49 -0700 Subject: [PATCH] config_loader: Don't check for sizes before using strcmp() Checking for a string size as expensive than comparing it with another string (maybe slightly faster because we're comparing with zeroes), but on average it will be more expensive because we need to check the full string. I wouldn't check for size unless we have any noticeable performance problems. Signed-off-by: Otavio Pontes --- src/config_loader.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/config_loader.c b/src/config_loader.c index d404f28a..4f4f943b 100644 --- a/src/config_loader.c +++ b/src/config_loader.c @@ -47,8 +47,6 @@ bool config_loader_set_opt(char *section, char *opt, char *value) char *lvalue = NULL; char *lsection = NULL; char *flag = NULL; - size_t opt_len; - size_t flag_len; bool ret = false; /* make sure the config loader has been initialized */ @@ -60,7 +58,6 @@ bool config_loader_set_opt(char *section, char *opt, char *value) /* replace all '_' used in config options with '-' used in flags */ flag = strdup_or_die(opt); - flag_len = strlen(flag); for (unsigned int i = 0; flag[i]; i++) { if (flag[i] == '_') { flag[i] = '-'; @@ -80,8 +77,7 @@ bool config_loader_set_opt(char *section, char *opt, char *value) /* search the option from within the available options */ while (options->name != NULL) { - opt_len = strlen(options->name); - if (flag_len == opt_len && strcmp(flag, options->name) == 0) { + if (strcmp(flag, options->name) == 0) { lvalue = str_tolower(value); /* some options don't have short options, only long, if this is the