From 4dd3abd41fe951b4c236c8e9920f17f3af7f4a6d Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 24 Dec 2013 11:20:52 -0500 Subject: [PATCH] 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. --- bufferevent-internal.h | 17 +++++++++++++++-- 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 @@ -252,17 +252,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) { -- 2.40.0