[PATCH] sndfile-util: reduce useless loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 at intel.com>
---
 src/pulsecore/sndfile-util.c |   22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/src/pulsecore/sndfile-util.c b/src/pulsecore/sndfile-util.c
index fe20486..d8cc244 100644
--- a/src/pulsecore/sndfile-util.c
+++ b/src/pulsecore/sndfile-util.c
@@ -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;
     }
-- 
1.7.9.5



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux