[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] pactl: optimized code

PulseAudio Marge Bot (@pulseaudio-merge-bot) gitlab at gitlab.freedesktop.org
Wed Jan 26 16:53:55 UTC 2022



PulseAudio Marge Bot pushed to branch master at PulseAudio / pulseaudio


Commits:
b8c15e87 by liaohanqin at 2022-01-25T16:09:32+08:00
pactl: optimized code

some if statements are redundant, use switch instead of it.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/686>

- - - - -


1 changed file:

- src/utils/pactl.c


Changes:

=====================================
src/utils/pactl.c
=====================================
@@ -2552,19 +2552,30 @@ static int parse_volume(const char *vol_spec, pa_volume_t *vol, enum volume_flag
     pa_xfree(vs);
 
     if (*vol_flags & VOL_RELATIVE) {
-        if ((*vol_flags & 0x0F) == VOL_UINT)
-            v += (double) PA_VOLUME_NORM;
-        if ((*vol_flags & 0x0F) == VOL_PERCENT)
-            v += 100.0;
-        if ((*vol_flags & 0x0F) == VOL_LINEAR)
-            v += 1.0;
-    }
-    if ((*vol_flags & 0x0F) == VOL_PERCENT)
-        v = v * (double) PA_VOLUME_NORM / 100;
-    if ((*vol_flags & 0x0F) == VOL_LINEAR)
-        v = pa_sw_volume_from_linear(v);
-    if ((*vol_flags & 0x0F) == VOL_DECIBEL)
-        v = pa_sw_volume_from_dB(v);
+	switch (*vol_flags & 0x0F) {
+	    case VOL_UINT:
+		v += (double) PA_VOLUME_NORM;
+		break;
+	    case VOL_PERCENT:
+		v += 100.0;
+		break;
+	    case VOL_LINEAR:
+		v += 1.0;
+		break;
+	}
+    }
+
+    switch (*vol_flags & 0x0F) {
+	case VOL_PERCENT:
+	    v = v * (double) PA_VOLUME_NORM / 100;
+	    break;
+	case VOL_LINEAR:
+	    v = pa_sw_volume_from_linear(v);
+	    break;
+	case VOL_DECIBEL:
+	    v = pa_sw_volume_from_dB(v);
+	    break;
+    }
 
     if (!PA_VOLUME_IS_VALID((pa_volume_t) v)) {
         pa_log(_("Volume outside permissible range.\n"));



View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/b8c15e87871905bb7aaead5dfaa62a6c745813a3

-- 
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/b8c15e87871905bb7aaead5dfaa62a6c745813a3
You're receiving this email because of your account on gitlab.freedesktop.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20220126/431af594/attachment-0001.htm>


More information about the pulseaudio-commits mailing list