diff options
author | Nicolas Pitre <nico@fluxnic.net> | 2021-03-19 17:31:43 -0400 |
---|---|---|
committer | Nicolas Pitre <nico@fluxnic.net> | 2021-03-20 15:54:32 -0400 |
commit | 3e20c44e07090eae146c3b6aef8a25ff78b67203 (patch) | |
tree | 86a935682a2219b8478e24a079df83d17efbb1b1 /src/conf.c | |
parent | db35f3bfb7cc256f7e2fcad27bb658370091128f (diff) |
optimize conf.c code part 1
Doing strlen() over and over is extremely unefficient.
Diffstat (limited to 'src/conf.c')
-rw-r--r-- | src/conf.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -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; |