respondd: simplify iteration in sorted list
This commit is contained in:
parent
b132dca1fc
commit
c74bbc23d5
|
@ -187,19 +187,15 @@ bool schedule_push_request(struct request_schedule *s, struct request_task *new_
|
||||||
// schedule is full
|
// schedule is full
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!s->list_head || s->list_head->scheduled_time > new_task->scheduled_time) {
|
// insert into sorted list
|
||||||
new_task->next = s->list_head;
|
struct request_task **pos;
|
||||||
s->list_head = new_task;
|
for (pos = &s->list_head; *pos; pos = &((*pos)->next)) {
|
||||||
} else {
|
if ((*pos)->scheduled_time > new_task->scheduled_time)
|
||||||
struct request_task *t;
|
|
||||||
for (t = s->list_head; t && t->next; t = t->next) {
|
|
||||||
if (t->next->scheduled_time > new_task->scheduled_time) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
// insert before *pos
|
||||||
new_task->next = t->next;
|
new_task->next = *pos;
|
||||||
t->next = new_task;
|
*pos = new_task;
|
||||||
}
|
|
||||||
|
|
||||||
s->length++;
|
s->length++;
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue