From 4e3fd05dbae8d3d47b08dc0044b1789c2b9d5908 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 18 Oct 2009 01:34:21 +0200 Subject: [PATCH] mpdclient: don't update the status in mpdclient_cmd_crop() This is kind of redundant, because it doesn't solve the theoretical race condition, and doesn't improve too much to justify the latency. --- src/mpdclient.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/mpdclient.c b/src/mpdclient.c index 04c1435..554e564 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -264,28 +264,24 @@ mpdclient_put_connection(struct mpdclient *c) bool mpdclient_cmd_crop(struct mpdclient *c) { - struct mpd_connection *connection = mpdclient_get_connection(c); - struct mpd_status *status; - bool playing; + struct mpd_connection *connection; int length, current; - if (connection == NULL) + if (c->status == NULL) return false; - status = mpd_run_status(connection); - if (status == NULL) - return mpdclient_handle_error(c); - - playing = mpd_status_get_state(status) == MPD_STATE_PLAY || - mpd_status_get_state(status) == MPD_STATE_PAUSE; - length = mpd_status_get_queue_length(status); - current = mpd_status_get_song_pos(status); - - mpd_status_free(status); - - if (!playing || length < 2) + length = mpd_status_get_queue_length(c->status); + current = mpd_status_get_song_pos(c->status); + if (current < 0 || + (mpd_status_get_state(c->status) != MPD_STATE_PLAY && + mpd_status_get_state(c->status) != MPD_STATE_PAUSE) || + mpd_status_get_queue_length(c->status) < 2) return true; + connection = mpdclient_get_connection(c); + if (connection == NULL) + return false; + mpd_command_list_begin(connection, false); while (--length >= 0) -- 2.30.2