From: Ian Jackson Date: Fri, 3 Oct 2014 20:43:39 +0000 (+0100) Subject: poll: Avoid duplicate array index counting X-Git-Tag: proposed.polypath.v4~55 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=commitdiff_plain;h=d613fd78298a9911b7917c06f3ea11de45462e76 poll: Avoid duplicate array index counting Calculate remain from idx at the top of the loop. This avoids having to keep both remain and idx in step. Signed-off-by: Ian Jackson --- diff --git a/secnet.c b/secnet.c index 7a9d3f0..6d08323 100644 --- a/secnet.c +++ b/secnet.c @@ -291,7 +291,7 @@ uint64_t now_global; static void run(void) { struct poll_interest *i; - int rv, nfds, remain, idx; + int rv, nfds, idx; int timeout; struct pollfd *fds=0; int allocdfds=0, shortfall=0; @@ -320,11 +320,11 @@ static void run(void) allocdfds += shortfall; fds=safe_realloc_ary(fds,sizeof(*fds),allocdfds, "run"); } - remain=allocdfds; shortfall=0; idx=0; timeout=-1; LIST_FOREACH(i, ®, entry) { + int remain=allocdfds-idx; nfds=remain; rv=i->before(i->state, fds+idx, &nfds, &timeout); if (rv!=0) { @@ -340,7 +340,6 @@ static void run(void) i->desc,timeout); } idx+=nfds; - remain-=nfds; i->nfds=nfds; } do {