From 84a9519cbf1ce3c89dcecf02354a46e3f3fd5ca2 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Tue, 20 Sep 2011 23:10:08 +0200 Subject: [PATCH] Simplify client_next/prev --- wmfs2/src/client.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/wmfs2/src/client.c b/wmfs2/src/client.c index 12297a8..87c7cbd 100644 --- a/wmfs2/src/client.c +++ b/wmfs2/src/client.c @@ -92,24 +92,20 @@ client_configure(struct client *c) struct client* client_next(struct client *c) { - struct client *next; + struct client *next = SLIST_NEXT(c, tnext); - if(!(next = SLIST_NEXT(c, tnext))) - next = SLIST_FIRST(&c->tag->clients); - - return next; + return (next ? next : SLIST_FIRST(&c->tag->clients)); } struct client* client_prev(struct client *c) { - struct client *cc; + struct client *nc, *cc = SLIST_FIRST(&c->tag->clients); - SLIST_FOREACH(cc, &c->tag->clients, tnext) - if(SLIST_NEXT(cc, tnext) == c || !SLIST_NEXT(cc, tnext)) - return cc; + while((nc = SLIST_NEXT(cc, tnext)) && nc != c) + cc = nc; - return SLIST_FIRST(&c->tag->clients); + return cc; } struct client*