summaryrefslogtreecommitdiffstats
path: root/src/conf.c
diff options
context:
space:
mode:
authorNicolas Pitre <nico@fluxnic.net>2021-03-19 17:31:43 -0400
committerNicolas Pitre <nico@fluxnic.net>2021-03-20 15:54:32 -0400
commit3e20c44e07090eae146c3b6aef8a25ff78b67203 (patch)
tree86a935682a2219b8478e24a079df83d17efbb1b1 /src/conf.c
parentdb35f3bfb7cc256f7e2fcad27bb658370091128f (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.c12
1 files changed, 6 insertions, 6 deletions
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;