Code

mpdclient: optimize crop with delete_range
authorMax Kellermann <max@duempel.org>
Sat, 17 Oct 2009 23:36:05 +0000 (01:36 +0200)
committerMax Kellermann <max@duempel.org>
Sat, 17 Oct 2009 23:36:05 +0000 (01:36 +0200)
MPD 0.16 supports "delete" with a range.

src/mpdclient.c

index 554e564af443451e046add42c3801c95cd02cbd9..97cf78b3d19df3b341519cab5a7c9acd217b55f9 100644 (file)
@@ -284,9 +284,15 @@ mpdclient_cmd_crop(struct mpdclient *c)
 
        mpd_command_list_begin(connection, false);
 
-       while (--length >= 0)
-               if (length != current)
-                       mpd_send_delete(connection, length);
+       if (mpd_connection_cmp_server_version(connection, 0, 16, 0) >= 0) {
+               if (current < length - 1)
+                       mpd_send_delete_range(connection, current + 1, length);
+               if (current > 0)
+                       mpd_send_delete_range(connection, 0, current);
+       } else
+               while (--length >= 0)
+                       if (length != current)
+                               mpd_send_delete(connection, length);
 
        mpd_command_list_end(connection);