aboutsummaryrefslogtreecommitdiffstats
path: root/src/Queue.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-08 16:51:21 +0100
committerMax Kellermann <max@duempel.org>2013-01-08 16:51:21 +0100
commitaffc446690d8dbda9e28cfcc2823b7dfc258ebba (patch)
tree54b7161294729da0046927fe5ac455e2d06d013b /src/Queue.cxx
parent255ee646c222c446f6cbf15737aeccf88d48517e (diff)
downloadmpd-affc446690d8dbda9e28cfcc2823b7dfc258ebba.tar.gz
mpd-affc446690d8dbda9e28cfcc2823b7dfc258ebba.tar.xz
mpd-affc446690d8dbda9e28cfcc2823b7dfc258ebba.zip
Queue: use std::stable_sort() instead of g_qsort_with_data()
Diffstat (limited to 'src/Queue.cxx')
-rw-r--r--src/Queue.cxx34
1 files changed, 8 insertions, 26 deletions
diff --git a/src/Queue.cxx b/src/Queue.cxx
index 345d13fb7..3fdb9ed1e 100644
--- a/src/Queue.cxx
+++ b/src/Queue.cxx
@@ -21,8 +21,6 @@
#include "Queue.hxx"
#include "song.h"
-#include <glib.h>
-
#include <stdlib.h>
queue::queue(unsigned _max_length)
@@ -280,26 +278,6 @@ queue::Clear()
length = 0;
}
-static gint
-queue_item_compare_order_priority(gconstpointer av, gconstpointer bv,
- gpointer user_data)
-{
- const struct queue *queue = (const struct queue *)user_data;
- const unsigned *const ap = (const unsigned *)av;
- const unsigned *const bp = (const unsigned *)bv;
- assert(ap >= queue->order && ap < queue->order + queue->length);
- assert(bp >= queue->order && bp < queue->order + queue->length);
- uint8_t a = queue->items[*ap].priority;
- uint8_t b = queue->items[*bp].priority;
-
- if (gcc_likely(a == b))
- return 0;
- else if (a > b)
- return -1;
- else
- return 1;
-}
-
static void
queue_sort_order_by_priority(struct queue *queue, unsigned start, unsigned end)
{
@@ -308,10 +286,14 @@ queue_sort_order_by_priority(struct queue *queue, unsigned start, unsigned end)
assert(start <= end);
assert(end <= queue->length);
- g_qsort_with_data(&queue->order[start], end - start,
- sizeof(queue->order[0]),
- queue_item_compare_order_priority,
- queue);
+ auto cmp = [queue](unsigned a_pos, unsigned b_pos){
+ const queue::Item &a = queue->items[a_pos];
+ const queue::Item &b = queue->items[b_pos];
+
+ return a.priority > b.priority;
+ };
+
+ std::stable_sort(queue->order + start, queue->order + end, cmp);
}
void