Code

mpdclient: don't update the status in mpdclient_cmd_crop()
authorMax Kellermann <max@duempel.org>
Sat, 17 Oct 2009 23:34:21 +0000 (01:34 +0200)
committerMax Kellermann <max@duempel.org>
Sat, 17 Oct 2009 23:34:21 +0000 (01:34 +0200)
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

index 04c1435e213441bc9f1219d7cff532525c280849..554e564af443451e046add42c3801c95cd02cbd9 100644 (file)
@@ -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)