switch-on-port-available: Improve readability

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.
This commit is contained in:
João Paulo Rechi Vita 2018-08-07 20:39:19 -07:00 committed by Tanu Kaskinen
parent 48021941a2
commit cefe037afc

View file

@ -156,7 +156,7 @@ static int try_to_switch_profile(pa_device_port *port) {
continue; continue;
/* Give a high bonus in case this is the preferred profile */ /* 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; prio += 1000000;
if (best_profile && best_prio >= prio) if (best_profile && best_prio >= prio)
@ -261,10 +261,19 @@ static void switch_from_port(pa_device_port *port) {
return; /* Already deselected */ return; /* Already deselected */
/* Try to find a good enough port to switch to */ /* Try to find a good enough port to switch to */
PA_HASHMAP_FOREACH(p, port->card->ports, state) PA_HASHMAP_FOREACH(p, port->card->ports, state) {
if (p->direction == port->direction && p != port && p->available != PA_AVAILABLE_NO && if (p == port)
(!best_port || best_port->priority < p->priority)) 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; 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"); pa_log_debug("Trying to switch away from port %s, found %s", port->name, best_port ? best_port->name : "no better option");