]> git.alsa-project.org Git - alsa-lib.git/commitdiff
conf: remove alloca() from snd_func_pcm_args_by_class()
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Thu, 14 Jul 2016 14:07:44 +0000 (23:07 +0900)
committerTakashi Iwai <tiwai@suse.de>
Thu, 14 Jul 2016 14:33:51 +0000 (16:33 +0200)
Both of alloca() and automatic variables keeps storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/confmisc.c

index 2275ccdcf4a6297ff7ce539e47d1d0b13e7187c8..99be48b8b6b67db388df43150d928eec2082d26f 100644 (file)
@@ -1053,7 +1053,7 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi
 {
        snd_config_t *n;
        snd_ctl_t *ctl = NULL;
-       snd_pcm_info_t *info;
+       snd_pcm_info_t info = {0};
        const char *id;
        int card = -1, dev;
        long class, index;
@@ -1091,7 +1091,6 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi
                goto __out;
        }
 
-       snd_pcm_info_alloca(&info);
        while(1) {
                err = snd_card_next(&card);
                if (err < 0) {
@@ -1106,7 +1105,6 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi
                        goto __out;
                }
                dev = -1;
-               memset(info, 0, snd_pcm_info_sizeof());
                while(1) {
                        err = snd_ctl_pcm_next_device(ctl, &dev);
                        if (err < 0) {
@@ -1115,11 +1113,11 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi
                        }
                        if (dev < 0)
                                break;
-                       snd_pcm_info_set_device(info, dev);
-                       err = snd_ctl_pcm_info(ctl, info);
+                       snd_pcm_info_set_device(&info, dev);
+                       err = snd_ctl_pcm_info(ctl, &info);
                        if (err < 0)
                                continue;
-                       if (snd_pcm_info_get_class(info) == (snd_pcm_class_t)class &&
+                       if (snd_pcm_info_get_class(&info) == (snd_pcm_class_t)class &&
                                        index == idx++)
                                goto __out;
                }