# HG changeset patch # User Matthew Wild # Date 1326687948 0 # Node ID df22d2e85fb077be890b25243a25325ba8e3f7ec # Parent f123677dd748ef5ed8a52640b95d0dc305501357 event_callback.c: Don't delete and re-add the event if the timeout hasn't changed diff -r f123677dd748 -r df22d2e85fb0 src/event_callback.c --- a/src/event_callback.c Mon Jan 16 04:21:17 2012 +0000 +++ b/src/event_callback.c Mon Jan 16 04:25:48 2012 +0000 @@ -22,7 +22,7 @@ le_callback* cb = p; lua_State* L; int ret; - double newTimeout = -1; + struct timeval new_tv = { 0, 0 }; assert(cb); if(!cb->base) return; /* Event has already been collected + destroyed */ @@ -34,13 +34,11 @@ if(!cb->base) return; /* event was destroyed during callback */ ret = lua_tointeger(L, -2); - if(lua_isnumber(L, -1)) { - newTimeout = lua_tonumber(L, -1); - if(newTimeout <= 0) { - memset(&cb->timeout, 0, sizeof(cb->timeout)); - } else { - load_timeval(newTimeout, &cb->timeout); - } + if(lua_isnumber(L, -1)) + { + double newTimeout = lua_tonumber(L, -1); + if(newTimeout>0) + load_timeval(newTimeout, &new_tv); } lua_pop(L, 2); if(ret == -1) { @@ -48,9 +46,10 @@ } else { struct event *ev = &cb->ev; int newEvent = ret; - /* NOTE: Currently, even if new timeout is the same as the old, a new event is setup regardless... */ - if(newEvent != event || newTimeout != -1) { // Need to hook up new event... + if( newEvent != event || (cb->timeout.tv_sec != new_tv.tv_sec || cb->timeout.tv_usec != new_tv.tv_usec) ) + { struct timeval *ptv = &cb->timeout; + cb->timeout = new_tv; if(!cb->timeout.tv_sec && !cb->timeout.tv_usec) ptv = NULL; event_del(ev);