]> code.delx.au - pulseaudio/commitdiff
sndfile-util: reduce useless loop
authorWang Xingchao <xingchao.wang@intel.com>
Mon, 7 May 2012 08:52:18 +0000 (16:52 +0800)
committerTanu Kaskinen <tanuk@iki.fi>
Wed, 19 Dec 2012 10:31:50 +0000 (12:31 +0200)
it's useless to get the same SF_FORMAT_INFO three times, just compare the
name/extention in the same loop.

Signed-off-by: Wang Xingchao <xingchao.wang@intel.com>
src/pulsecore/sndfile-util.c

index fe2048641393968242f17f629dc6de3ddfa0d383..d8cc24453f88f9426d1075a33cc91677b01b0654 100644 (file)
@@ -424,7 +424,6 @@ int pa_sndfile_format_from_string(const char *name) {
 
     pa_assert_se(sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT, &count, sizeof(int)) == 0);
 
-    /* First try to match via full type string */
     for (i = 0; i < count; i++) {
         SF_FORMAT_INFO fi;
         pa_zero(fi);
@@ -432,30 +431,15 @@ int pa_sndfile_format_from_string(const char *name) {
 
         pa_assert_se(sf_command(NULL, SFC_GET_FORMAT_MAJOR, &fi, sizeof(fi)) == 0);
 
+       /* First try to match via full type string */
         if (strcasecmp(name, fi.name) == 0)
             return fi.format;
-    }
-
-    /* Then, try to match via the full extension */
-    for (i = 0; i < count; i++) {
-        SF_FORMAT_INFO fi;
-        pa_zero(fi);
-        fi.format = i;
-
-        pa_assert_se(sf_command(NULL, SFC_GET_FORMAT_MAJOR, &fi, sizeof(fi)) == 0);
 
+       /* Then, try to match via the full extension */
         if (strcasecmp(name, fi.extension) == 0)
             return fi.format;
-    }
-
-    /* Then, try to match via the start of the type string */
-    for (i = 0; i < count; i++) {
-        SF_FORMAT_INFO fi;
-        pa_zero(fi);
-        fi.format = i;
-
-        pa_assert_se(sf_command(NULL, SFC_GET_FORMAT_MAJOR, &fi, sizeof(fi)) == 0);
 
+       /* Then, try to match via the start of the type string */
         if (strncasecmp(name, fi.name, strlen(name)) == 0)
             return fi.format;
     }