respondd: simplify iteration in sorted list

This commit is contained in:
lemoer 2016-09-02 01:36:06 +02:00
parent b132dca1fc
commit c74bbc23d5
1 changed files with 8 additions and 12 deletions

View File

@ -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; break;
for (t = s->list_head; t && t->next; t = t->next) {
if (t->next->scheduled_time > new_task->scheduled_time) {
break;
}
}
new_task->next = t->next;
t->next = new_task;
} }
// insert before *pos
new_task->next = *pos;
*pos = new_task;
s->length++; s->length++;
return true; return true;