diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-12-24 11:20:52 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-12-24 11:20:52 -0500 |
commit | 4dd3abd41fe951b4c236c8e9920f17f3af7f4a6d (patch) | |
tree | 419c40029034bcd98e82cff1dd86362e2520c5b8 | |
parent | b4ef3def6f8d7dd9f6582b85be4539426ac04799 (diff) | |
download | libevent-4dd3abd41fe951b4c236c8e9920f17f3af7f4a6d.tar.gz |
Make bufferevent_trigger_nolock_() inline
Since most of its callers are using constant EV_READ or EV_WRITE, and
using constant 0 as its argument, this should eliminate most of the
overhead for this function in the fast case.
-rw-r--r-- | bufferevent-internal.h | 17 | ||||
-rw-r--r-- | bufferevent.c | 11 |
2 files changed, 15 insertions, 13 deletions
diff --git a/bufferevent-internal.h b/bufferevent-internal.h index 70b25cd9..f85f376e 100644 --- a/bufferevent-internal.h +++ b/bufferevent-internal.h @@ -354,8 +354,21 @@ void bufferevent_run_eventcb_(struct bufferevent *bufev, short what, int options * BEV_TRIG_DEFER_CALLBACKS) I/O callbacks specified in iotype. * Must already hold the bufev lock. Honors watermarks unless * BEV_TRIG_IGNORE_WATERMARKS is in options. */ -void bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options); - +static inline void bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options); + +/* Making this inline since all of the common-case calls to this function in + * libevent use constant arguments. */ +size_t evbuffer_get_length(const struct evbuffer *buf); +static inline void +bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options) +{ + if ((iotype & EV_READ) && ((options & BEV_TRIG_IGNORE_WATERMARKS) || + evbuffer_get_length(bufev->input) >= bufev->wm_read.low)) + bufferevent_run_readcb_(bufev, options); + if ((iotype & EV_WRITE) && ((options & BEV_TRIG_IGNORE_WATERMARKS) || + evbuffer_get_length(bufev->output) <= bufev->wm_write.low)) + bufferevent_run_writecb_(bufev, options); +} /** Internal: Add the event 'ev' with timeout tv, unless tv is set to 0, in * which case add ev with no timeout. */ diff --git a/bufferevent.c b/bufferevent.c index d8c84da4..19413369 100644 --- a/bufferevent.c +++ b/bufferevent.c @@ -253,17 +253,6 @@ bufferevent_run_writecb_(struct bufferevent *bufev, int options) } void -bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options) -{ - if ((iotype & EV_READ) && ((options & BEV_TRIG_IGNORE_WATERMARKS) || - evbuffer_get_length(bufev->input) >= bufev->wm_read.low)) - bufferevent_run_readcb_(bufev, options); - if ((iotype & EV_WRITE) && ((options & BEV_TRIG_IGNORE_WATERMARKS) || - evbuffer_get_length(bufev->output) <= bufev->wm_write.low)) - bufferevent_run_writecb_(bufev, options); -} - -void bufferevent_trigger(struct bufferevent *bufev, short iotype, int options) { bufferevent_incref_and_lock_(bufev); |