[PATCH 2/7] switch-on-port-available: Improve readability

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

 



Split a big conditional into separate checks and use pa_safe_streq
instead of checking if a pointer is valid and calling pa_streq inside a
conditional.
---
 src/modules/module-switch-on-port-available.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/modules/module-switch-on-port-available.c b/src/modules/module-switch-on-port-available.c
index 321db361f..385c2f693 100644
--- a/src/modules/module-switch-on-port-available.c
+++ b/src/modules/module-switch-on-port-available.c
@@ -156,7 +156,7 @@ static int try_to_switch_profile(pa_device_port *port) {
             continue;
 
         /* Give a high bonus in case this is the preferred profile */
-        if (port->preferred_profile && pa_streq(name ? name : profile->name, port->preferred_profile))
+        if (pa_safe_streq(name ? name : profile->name, port->preferred_profile))
             prio += 1000000;
 
         if (best_profile && best_prio >= prio)
@@ -261,10 +261,19 @@ static void switch_from_port(pa_device_port *port) {
         return; /* Already deselected */
 
     /* Try to find a good enough port to switch to */
-    PA_HASHMAP_FOREACH(p, port->card->ports, state)
-        if (p->direction == port->direction && p != port && p->available != PA_AVAILABLE_NO &&
-           (!best_port || best_port->priority < p->priority))
+    PA_HASHMAP_FOREACH(p, port->card->ports, state) {
+        if (p == port)
+            continue;
+
+        if (p->available == PA_AVAILABLE_NO)
+            continue;
+
+        if (p->direction != port->direction)
+            continue;
+
+        if (!best_port || best_port->priority < p->priority)
            best_port = p;
+    }
 
     pa_log_debug("Trying to switch away from port %s, found %s", port->name, best_port ? best_port->name : "no better option");
 
-- 
2.18.0



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

  Powered by Linux