From: Max Kellermann Date: Sun, 19 Mar 2017 12:10:43 +0000 (+0100) Subject: mpdclient: eliminate redundant mpd_status_get_volume() calls X-Git-Tag: v0.26~20 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=86e6f3ac2a45025a7a66655eb0e406a02cee0769;p=ncmpc.git mpdclient: eliminate redundant mpd_status_get_volume() calls Return early from mpdclient_cmd_volume_*(), without calling mpdclient_get_connection(), if we already know the operation would have no effect. --- diff --git a/src/mpdclient.c b/src/mpdclient.c index a4e165e..73bb85f 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -409,39 +409,26 @@ mpdclient_cmd_volume(struct mpdclient *c, gint value) bool mpdclient_cmd_volume_up(struct mpdclient *c) { + if (c->volume < 0 || c->volume >= 100) + return true; + struct mpd_connection *connection = mpdclient_get_connection(c); if (connection == NULL) return false; - if (c->status == NULL || - mpd_status_get_volume(c->status) == -1) - return true; - - if (c->volume < 0) - c->volume = mpd_status_get_volume(c->status); - - if (c->volume >= 100) - return true; - return mpdclient_cmd_volume(c, ++c->volume); } bool mpdclient_cmd_volume_down(struct mpdclient *c) { + if (c->volume <= 0) + return true; + struct mpd_connection *connection = mpdclient_get_connection(c); if (connection == NULL) return false; - if (c->status == NULL || mpd_status_get_volume(c->status) < 0) - return true; - - if (c->volume < 0) - c->volume = mpd_status_get_volume(c->status); - - if (c->volume <= 0) - return true; - return mpdclient_cmd_volume(c, --c->volume); }