From 3e20c44e07090eae146c3b6aef8a25ff78b67203 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Fri, 19 Mar 2021 17:31:43 -0400 Subject: optimize conf.c code part 1 Doing strlen() over and over is extremely unefficient. --- src/conf.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/conf.c') diff --git a/src/conf.c b/src/conf.c index 67d54bf..5167ada 100644 --- a/src/conf.c +++ b/src/conf.c @@ -132,14 +132,14 @@ char * get_conf_values(char * salida) { if (user_conf_d == NULL) return NULL; struct nlist * nl; - nl = user_conf_d->list; salida[0]='\0'; - while (nl != NULL) { + + char *buf = salida; + for (nl = user_conf_d->list; nl != NULL; nl = nl->next) { // ignore version conf variable here so that its not shown in :set command - if (! strcmp(nl->key, "version")) { nl = nl->next; continue; } + if (! strcmp(nl->key, "version")) continue; - sprintf(salida + strlen(salida), "%s=%s\n", nl->key, nl->val); - nl = nl->next; + buf += sprintf(buf, "%s=%s\n", nl->key, nl->val); } return salida; } @@ -161,7 +161,7 @@ char * get_conf_values(char * salida) { char * get_conf_value(char * key) { char * val = get(user_conf_d, key); - if ( val == NULL || *(&val[0]) == '\0') + if (val == NULL || val[0] == '\0') return get(predefined_conf_d, key); else return val; -- cgit v1.2.3