Optimized index-search functions

This commit is contained in:
Jaroslav Kysela 2001-06-18 11:44:45 +00:00
parent f1fe5d5fb2
commit 9e9e10c1bd

View file

@ -216,7 +216,7 @@ int snd_func_getenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src, v
snd_config_t *n, *d; snd_config_t *n, *d;
snd_config_iterator_t i, next; snd_config_iterator_t i, next;
char *res, *def = NULL; char *res, *def = NULL;
int idx = 0, err; int idx = 0, err, hit;
err = snd_config_search(src, "vars", &n); err = snd_config_search(src, "vars", &n);
if (err < 0) { if (err < 0) {
@ -243,7 +243,8 @@ int snd_func_getenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src, v
SNDERR("error getting field default"); SNDERR("error getting field default");
goto __error; goto __error;
} }
__retry: do {
hit = 0;
snd_config_for_each(i, next, n) { snd_config_for_each(i, next, n) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n); const char *id = snd_config_get_id(n);
@ -268,9 +269,10 @@ int snd_func_getenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src, v
res = strdup(env); res = strdup(env);
goto __ok; goto __ok;
} }
goto __retry; hit = 1;
} }
} }
} while (hit);
res = def; res = def;
def = NULL; def = NULL;
__ok: __ok:
@ -319,7 +321,7 @@ int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src, v
snd_config_t *n; snd_config_t *n;
snd_config_iterator_t i, next; snd_config_iterator_t i, next;
char *res = NULL, *tmp; char *res = NULL, *tmp;
int idx = 0, len = 0, len1, err; int idx = 0, len = 0, len1, err, hit;
err = snd_config_search(src, "strings", &n); err = snd_config_search(src, "strings", &n);
if (err < 0) { if (err < 0) {
@ -331,7 +333,8 @@ int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src, v
SNDERR("error evaluating strings"); SNDERR("error evaluating strings");
goto __error; goto __error;
} }
__retry: do {
hit = 0;
snd_config_for_each(i, next, n) { snd_config_for_each(i, next, n) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
char *ptr; char *ptr;
@ -360,9 +363,10 @@ int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src, v
len += len1; len += len1;
tmp[len] = '\0'; tmp[len] = '\0';
res = tmp; res = tmp;
goto __retry; hit = 1;
} }
} }
} while (hit);
if (res == NULL) { if (res == NULL) {
SNDERR("empty string is not accepted"); SNDERR("empty string is not accepted");
err = -EINVAL; err = -EINVAL;