mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-12-15 08:56:36 -05:00
Optimized index-search functions
This commit is contained in:
parent
f1fe5d5fb2
commit
9e9e10c1bd
1 changed files with 61 additions and 57 deletions
118
src/confmisc.c
118
src/confmisc.c
|
|
@ -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,34 +243,36 @@ 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 {
|
||||||
snd_config_for_each(i, next, n) {
|
hit = 0;
|
||||||
snd_config_t *n = snd_config_iterator_entry(i);
|
snd_config_for_each(i, next, n) {
|
||||||
const char *id = snd_config_get_id(n);
|
snd_config_t *n = snd_config_iterator_entry(i);
|
||||||
const char *ptr, *env;
|
const char *id = snd_config_get_id(n);
|
||||||
long i;
|
const char *ptr, *env;
|
||||||
if (snd_config_get_type(n) != SND_CONFIG_TYPE_STRING) {
|
long i;
|
||||||
SNDERR("field %s is not a string", id);
|
if (snd_config_get_type(n) != SND_CONFIG_TYPE_STRING) {
|
||||||
err = -EINVAL;
|
SNDERR("field %s is not a string", id);
|
||||||
goto __error;
|
err = -EINVAL;
|
||||||
}
|
goto __error;
|
||||||
err = safe_strtol(id, &i);
|
}
|
||||||
if (err < 0) {
|
err = safe_strtol(id, &i);
|
||||||
SNDERR("id of field %s is not an integer", id);
|
if (err < 0) {
|
||||||
err = -EINVAL;
|
SNDERR("id of field %s is not an integer", id);
|
||||||
goto __error;
|
err = -EINVAL;
|
||||||
}
|
goto __error;
|
||||||
if (i == idx) {
|
}
|
||||||
idx++;
|
if (i == idx) {
|
||||||
snd_config_get_string(n, &ptr);
|
idx++;
|
||||||
env = getenv(ptr);
|
snd_config_get_string(n, &ptr);
|
||||||
if (env != NULL && *env != '\0') {
|
env = getenv(ptr);
|
||||||
res = strdup(env);
|
if (env != NULL && *env != '\0') {
|
||||||
goto __ok;
|
res = strdup(env);
|
||||||
|
goto __ok;
|
||||||
|
}
|
||||||
|
hit = 1;
|
||||||
}
|
}
|
||||||
goto __retry;
|
|
||||||
}
|
}
|
||||||
}
|
} 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,38 +333,40 @@ 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 {
|
||||||
snd_config_for_each(i, next, n) {
|
hit = 0;
|
||||||
snd_config_t *n = snd_config_iterator_entry(i);
|
snd_config_for_each(i, next, n) {
|
||||||
char *ptr;
|
snd_config_t *n = snd_config_iterator_entry(i);
|
||||||
const char *id = snd_config_get_id(n);
|
char *ptr;
|
||||||
long i;
|
const char *id = snd_config_get_id(n);
|
||||||
err = safe_strtol(id, &i);
|
long i;
|
||||||
if (err < 0) {
|
err = safe_strtol(id, &i);
|
||||||
SNDERR("id of field %s is not an integer", id);
|
if (err < 0) {
|
||||||
err = -EINVAL;
|
SNDERR("id of field %s is not an integer", id);
|
||||||
goto __error;
|
err = -EINVAL;
|
||||||
}
|
|
||||||
if (i == idx) {
|
|
||||||
idx++;
|
|
||||||
snd_config_get_ascii(n, &ptr);
|
|
||||||
len1 = strlen(ptr);
|
|
||||||
tmp = realloc(res, len + len1 + 1);
|
|
||||||
if (tmp == NULL) {
|
|
||||||
free(ptr);
|
|
||||||
if (res)
|
|
||||||
free(res);
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto __error;
|
goto __error;
|
||||||
}
|
}
|
||||||
memcpy(tmp + len, ptr, len1);
|
if (i == idx) {
|
||||||
free(ptr);
|
idx++;
|
||||||
len += len1;
|
snd_config_get_ascii(n, &ptr);
|
||||||
tmp[len] = '\0';
|
len1 = strlen(ptr);
|
||||||
res = tmp;
|
tmp = realloc(res, len + len1 + 1);
|
||||||
goto __retry;
|
if (tmp == NULL) {
|
||||||
|
free(ptr);
|
||||||
|
if (res)
|
||||||
|
free(res);
|
||||||
|
err = -ENOMEM;
|
||||||
|
goto __error;
|
||||||
|
}
|
||||||
|
memcpy(tmp + len, ptr, len1);
|
||||||
|
free(ptr);
|
||||||
|
len += len1;
|
||||||
|
tmp[len] = '\0';
|
||||||
|
res = tmp;
|
||||||
|
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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue