From c74bbc23d538b3aa4e311dbe9a39ffcf49b3777d Mon Sep 17 00:00:00 2001 From: lemoer Date: Fri, 2 Sep 2016 01:36:06 +0200 Subject: [PATCH] respondd: simplify iteration in sorted list --- net/respondd/src/respondd.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/net/respondd/src/respondd.c b/net/respondd/src/respondd.c index dc4cf2b..8cd6e29 100644 --- a/net/respondd/src/respondd.c +++ b/net/respondd/src/respondd.c @@ -187,19 +187,15 @@ bool schedule_push_request(struct request_schedule *s, struct request_task *new_ // schedule is full return false; - if (!s->list_head || s->list_head->scheduled_time > new_task->scheduled_time) { - new_task->next = s->list_head; - s->list_head = new_task; - } else { - 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; - } - } - new_task->next = t->next; - t->next = new_task; + // insert into sorted list + struct request_task **pos; + for (pos = &s->list_head; *pos; pos = &((*pos)->next)) { + if ((*pos)->scheduled_time > new_task->scheduled_time) + break; } + // insert before *pos + new_task->next = *pos; + *pos = new_task; s->length++; return true;