mirror of
https://github.com/libretro/RetroArch
synced 2025-02-11 15:40:28 +00:00
Simplify msg_queue_pull
This commit is contained in:
parent
97567a5c9a
commit
707a5eaf0f
@ -124,10 +124,7 @@ void msg_queue_clear(msg_queue_t *queue)
|
|||||||
|
|
||||||
const char *msg_queue_pull(msg_queue_t *queue)
|
const char *msg_queue_pull(msg_queue_t *queue)
|
||||||
{
|
{
|
||||||
struct queue_elem *front = NULL;
|
struct queue_elem *front = NULL, *last = NULL, *parent = NULL, *child = NULL;
|
||||||
struct queue_elem *last = NULL;
|
|
||||||
struct queue_elem *parent = NULL;
|
|
||||||
struct queue_elem *child = NULL;
|
|
||||||
size_t tmp_ptr = 1;
|
size_t tmp_ptr = 1;
|
||||||
|
|
||||||
(void)parent;
|
(void)parent;
|
||||||
@ -142,48 +139,46 @@ const char *msg_queue_pull(msg_queue_t *queue)
|
|||||||
front->duration--;
|
front->duration--;
|
||||||
if (front->duration > 0)
|
if (front->duration > 0)
|
||||||
return front->msg;
|
return front->msg;
|
||||||
else
|
|
||||||
|
free(queue->tmp_msg);
|
||||||
|
queue->tmp_msg = front->msg;
|
||||||
|
front->msg = NULL;
|
||||||
|
|
||||||
|
front = (struct queue_elem*)queue->elems[1];
|
||||||
|
last = (struct queue_elem*)queue->elems[--queue->ptr];
|
||||||
|
queue->elems[1] = last;
|
||||||
|
free(front);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
{
|
{
|
||||||
free(queue->tmp_msg);
|
bool left = (tmp_ptr * 2 <= queue->ptr)
|
||||||
queue->tmp_msg = front->msg;
|
&& (queue->elems[tmp_ptr] < queue->elems[tmp_ptr * 2]);
|
||||||
front->msg = NULL;
|
bool right = (tmp_ptr * 2 + 1 <= queue->ptr)
|
||||||
|
&& (queue->elems[tmp_ptr] < queue->elems[tmp_ptr * 2 + 1]);
|
||||||
|
|
||||||
front = (struct queue_elem*)queue->elems[1];
|
if (!left && !right)
|
||||||
last = (struct queue_elem*)queue->elems[--queue->ptr];
|
break;
|
||||||
queue->elems[1] = last;
|
|
||||||
free(front);
|
|
||||||
|
|
||||||
for (;;)
|
size_t switch_index = tmp_ptr;
|
||||||
|
if (left && !right)
|
||||||
|
switch_index <<= 1;
|
||||||
|
else if (right && !left)
|
||||||
|
switch_index += switch_index + 1;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
bool left = (tmp_ptr * 2 <= queue->ptr)
|
if (queue->elems[tmp_ptr * 2]
|
||||||
&& (queue->elems[tmp_ptr] < queue->elems[tmp_ptr * 2]);
|
>= queue->elems[tmp_ptr * 2 + 1])
|
||||||
bool right = (tmp_ptr * 2 + 1 <= queue->ptr)
|
|
||||||
&& (queue->elems[tmp_ptr] < queue->elems[tmp_ptr * 2 + 1]);
|
|
||||||
|
|
||||||
if (!left && !right)
|
|
||||||
break;
|
|
||||||
|
|
||||||
size_t switch_index = tmp_ptr;
|
|
||||||
if (left && !right)
|
|
||||||
switch_index <<= 1;
|
switch_index <<= 1;
|
||||||
else if (right && !left)
|
|
||||||
switch_index += switch_index + 1;
|
|
||||||
else
|
else
|
||||||
{
|
switch_index += switch_index + 1;
|
||||||
if (queue->elems[tmp_ptr * 2]
|
|
||||||
>= queue->elems[tmp_ptr * 2 + 1])
|
|
||||||
switch_index <<= 1;
|
|
||||||
else
|
|
||||||
switch_index += switch_index + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
parent = (struct queue_elem*)queue->elems[tmp_ptr];
|
|
||||||
child = (struct queue_elem*)queue->elems[switch_index];
|
|
||||||
queue->elems[tmp_ptr] = child;
|
|
||||||
queue->elems[switch_index] = parent;
|
|
||||||
tmp_ptr = switch_index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return queue->tmp_msg;
|
parent = (struct queue_elem*)queue->elems[tmp_ptr];
|
||||||
|
child = (struct queue_elem*)queue->elems[switch_index];
|
||||||
|
queue->elems[tmp_ptr] = child;
|
||||||
|
queue->elems[switch_index] = parent;
|
||||||
|
tmp_ptr = switch_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return queue->tmp_msg;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user