diff --git a/core/deck.cpp b/core/deck.cpp index 0b2f86cb..60d2f2f8 100644 --- a/core/deck.cpp +++ b/core/deck.cpp @@ -77,6 +77,20 @@ struct queue *tempq_alloc(struct queue_ops *ops, unsigned int flags) return queue; } +void tempq_free(struct queue *queue) +{ + std::list::iterator it; + + for (it = queue_deck.begin(); it != queue_deck.end(); it++) { + if (&(*it) == queue) { + queue_deck.erase(it); + deck :: write(); + return; + } + } + return; +} + void deck :: write() { std::list::iterator it; @@ -98,24 +112,6 @@ void deck :: save(struct queue *queue, enum queue_flags flag) deck :: write(); } -static void _destroy(std::list::iterator &it) -{ - queue_deck.erase(it); - deck :: write(); -} - -void deck :: destroy(queue *queue) -{ - std::list::iterator it; - - for (it = queue_deck.begin(); it != queue_deck.end(); it++) { - if (&(*it) == queue) { - _destroy(it); - return; - } - } -} - void deck :: move(queue *queue, unsigned int index) { unsigned int old_pos = deck :: index(queue); @@ -174,7 +170,7 @@ struct track *deck :: next() track = queue_next(&(*it)); if (queue_size(&(*it)) == 0) - _destroy(it); + tempq_free(&(*it)); break; } diff --git a/gui/queue.cpp b/gui/queue.cpp index adbb18bf..274a9559 100644 --- a/gui/queue.cpp +++ b/gui/queue.cpp @@ -172,7 +172,7 @@ void QueueTab :: on_move_queue(int num) void QueueTab :: on_close_clicked() { - deck :: destroy(tab_pq); + tempq_free(tab_pq); delete this; } diff --git a/include/core/deck.h b/include/core/deck.h index b44128ae..b2534897 100644 --- a/include/core/deck.h +++ b/include/core/deck.h @@ -46,13 +46,6 @@ namespace deck void write(); void save(struct queue *, enum queue_flags); - /** - * Removes the queue from the deck. - * - * @param queue The queue to be removed. - */ - void destroy(queue *); - /** * Move the queue to a new location in the deck. * @@ -98,4 +91,7 @@ void tempq_init(struct queue_ops *); /* Called to allocate a new temporary queue. */ struct queue *tempq_alloc(struct queue_ops *, unsigned int); +/* Called to free a temporary queue. */ +void tempq_free(struct queue *); + #endif /* OCARINA_CORE_DECK_H */ diff --git a/tests/core/deck.cpp b/tests/core/deck.cpp index f8fb7693..ee514eda 100644 --- a/tests/core/deck.cpp +++ b/tests/core/deck.cpp @@ -48,8 +48,8 @@ static void test_tempq() test_equal(queue_has_flag(q1, Q_SAVE_SORT), true); test_equal(queue_has_flag(q1, Q_SAVE_FLAGS), true); - deck :: destroy(q0); - deck :: destroy(q1); + tempq_free(q0); + tempq_free(q1); history_deinit(); collection_deinit(); playlist_deinit(); @@ -90,11 +90,11 @@ static void test_create_mv_destroy() deck :: move(q1, 2); test_equal(deck :: index(q1), (unsigned)2); - deck :: destroy(q1); + tempq_free(q1); test_equal(deck :: index(q1), (unsigned)3); test_equal(deck :: index(q2), (unsigned)2); - deck :: destroy(q2); + tempq_free(q2); test_equal(deck :: index(q2), (unsigned)2); test_equal(deck :: get(3), Q_NULL);