From 8d2b0caf6cbe27a49432f8fe00d50318b23f6b42 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 21 Jan 2016 10:42:20 -0500 Subject: [PATCH] core/tempq: Store queue operations passed to tempq_init() We don't need different operations for each queue. If we store this then a higher layer doesn't need to keep passing the same structure over and over again. Signed-off-by: Anna Schumaker --- core/tempq.c | 18 +++++++++++------- gui/tabs.cpp | 2 +- include/core/tempq.h | 2 +- tests/core/audio.c | 2 +- tests/core/tempq.c | 8 ++++---- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/core/tempq.c b/core/tempq.c index 504f6b6c..15bdb65a 100644 --- a/core/tempq.c +++ b/core/tempq.c @@ -7,15 +7,17 @@ #include #include +static struct queue_ops *tempq_ops = NULL; static GSList *tempq_list; static struct file tempq_file; -static struct queue *__tempq_alloc(struct queue_ops *ops, unsigned int flags) +static struct queue *__tempq_alloc(unsigned int flags) { struct queue *queue = g_malloc(sizeof(struct queue)); + flags = flags | Q_SAVE_FLAGS | Q_SAVE_SORT; tempq_list = g_slist_append(tempq_list, queue); - queue_init(queue, flags | Q_SAVE_FLAGS | Q_SAVE_SORT, ops); + queue_init(queue, flags, tempq_ops); return queue; } @@ -26,13 +28,13 @@ static void __tempq_free(struct queue *queue) g_free(queue); } -static void __tempq_read_queue(struct queue_ops *ops) +static void __tempq_read_queue() { unsigned int flags, count, i, track; struct queue *queue; file_readf(&tempq_file, "%u %u", &flags, &count); - queue = __tempq_alloc(ops, flags); + queue = __tempq_alloc(flags); for (i = 0; i < count; i++) { file_readf(&tempq_file, "%u", &track); @@ -58,6 +60,8 @@ void tempq_init(struct queue_ops *ops) { unsigned int num, i; + tempq_ops = ops; + file_init(&tempq_file, "deck", 1); if (!file_open(&tempq_file, OPEN_READ)) return; @@ -66,7 +70,7 @@ void tempq_init(struct queue_ops *ops) file_readf(&tempq_file, "%u", &num); for (i = 0; i < num; i++) - __tempq_read_queue(ops); + __tempq_read_queue(); out: file_close(&tempq_file); } @@ -91,9 +95,9 @@ void tempq_save(struct queue *queue, enum queue_flags flag) file_close(&tempq_file); } -struct queue *tempq_alloc(struct queue_ops *ops, unsigned int flags) +struct queue *tempq_alloc(unsigned int flags) { - struct queue *queue = __tempq_alloc(ops, Q_ENABLED | flags); + struct queue *queue = __tempq_alloc(Q_ENABLED | flags); tempq_save(queue, Q_ENABLED); return queue; } diff --git a/gui/tabs.cpp b/gui/tabs.cpp index da351c62..c340d4ff 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -178,7 +178,7 @@ bool Tab :: tab_queue_selected(bool random) if (tempq_count() >= 10) return true; - queue *pq = tempq_alloc(&tempq_ops, flags); + queue *pq = tempq_alloc(flags); on_pq_created(pq, tempq_count() - 1); gui_sidebar_add(gui_queue(pq)); tab_queue_add(pq); diff --git a/include/core/tempq.h b/include/core/tempq.h index 2069567d..18bd5cf7 100644 --- a/include/core/tempq.h +++ b/include/core/tempq.h @@ -25,7 +25,7 @@ void tempq_save(struct queue *, enum queue_flags); /* Called to allocate a new temporary queue. */ -struct queue *tempq_alloc(struct queue_ops *, unsigned int); +struct queue *tempq_alloc(unsigned int); /* Called to free a temporary queue. */ void tempq_free(struct queue *); diff --git a/tests/core/audio.c b/tests/core/audio.c index 83f42217..277cbadf 100644 --- a/tests/core/audio.c +++ b/tests/core/audio.c @@ -128,7 +128,7 @@ static void test_playback() static void test_next() { struct queue *history_q = history_get_queue(); - struct queue *temp_q = tempq_alloc(NULL, 0); + struct queue *temp_q = tempq_alloc(0); int i; state_count = 0; diff --git a/tests/core/tempq.c b/tests/core/tempq.c index 2a3144df..447bf1c2 100644 --- a/tests/core/tempq.c +++ b/tests/core/tempq.c @@ -32,7 +32,7 @@ static void test_alloc() { struct queue *q0, *q1; - q0 = tempq_alloc(NULL, 0); + q0 = tempq_alloc(0); test_not_equal((void *)q0, NULL); test_equal(queue_has_flag(q0, Q_ENABLED), (bool)true); test_equal(queue_has_flag(q0, Q_RANDOM), (bool)false); @@ -42,7 +42,7 @@ static void test_alloc() test_equal(tempq_count(), 1); test_equal(tempq_index(q0), 0); - q1 = tempq_alloc(NULL, Q_RANDOM); + q1 = tempq_alloc(Q_RANDOM); test_not_equal((void *)q1, NULL); test_equal(queue_has_flag(q1, Q_ENABLED), (bool)true); test_equal(queue_has_flag(q1, Q_RANDOM), (bool)true); @@ -116,8 +116,8 @@ static void test_next() collection_add("tests/Music/Hyrule Symphony"); while (idle_run_task()) {}; - q0 = tempq_alloc(NULL, 0); - q1 = tempq_alloc(NULL, 0); + q0 = tempq_alloc(0); + q1 = tempq_alloc(0); for (i = 0; i < track_db->db_size; i++) { queue_add(q0, track_get(i)); queue_add(q1, track_get(i));