From d613fd78298a9911b7917c06f3ea11de45462e76 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 3 Oct 2014 21:43:39 +0100 Subject: [PATCH] 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 --- secnet.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 { -- 2.11.0