diff options
author | Jim Jagielski <jim@apache.org> | 2011-01-27 19:44:50 +0000 |
---|---|---|
committer | Jim Jagielski <jim@apache.org> | 2011-01-27 19:44:50 +0000 |
commit | f6a8411d1b1ea938f77cebc0f5403163d3e2656b (patch) | |
tree | c637505b5e9e31a9b5486078ba18a42bb9041e58 /util-misc | |
parent | d7112cd949520ac3cd253c18a9aa1177fc1d960f (diff) | |
download | apr-f6a8411d1b1ea938f77cebc0f5403163d3e2656b.tar.gz |
replace expensive % with faster (2-4x) functional equiv.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1064276 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'util-misc')
-rw-r--r-- | util-misc/apr_queue.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/util-misc/apr_queue.c b/util-misc/apr_queue.c index 66b74dcea..413069918 100644 --- a/util-misc/apr_queue.c +++ b/util-misc/apr_queue.c @@ -185,7 +185,9 @@ APR_DECLARE(apr_status_t) apr_queue_push(apr_queue_t *queue, void *data) } queue->data[queue->in] = data; - queue->in = (queue->in + 1) % queue->bounds; + queue->in++; + if (queue->in >= queue->bounds) + queue->in -= queue->bounds; queue->nelts++; if (queue->empty_waiters) { @@ -225,7 +227,9 @@ APR_DECLARE(apr_status_t) apr_queue_trypush(apr_queue_t *queue, void *data) } queue->data[queue->in] = data; - queue->in = (queue->in + 1) % queue->bounds; + queue->in++; + if (queue->in >= queue->bounds) + queue->in -= queue->bounds; queue->nelts++; if (queue->empty_waiters) { @@ -297,7 +301,9 @@ APR_DECLARE(apr_status_t) apr_queue_pop(apr_queue_t *queue, void **data) *data = queue->data[queue->out]; queue->nelts--; - queue->out = (queue->out + 1) % queue->bounds; + queue->out++; + if (queue->out >= queue->bounds) + queue->out -= queue->bounds; if (queue->full_waiters) { Q_DBG("signal !full", queue); rv = apr_thread_cond_signal(queue->not_full); @@ -337,7 +343,9 @@ APR_DECLARE(apr_status_t) apr_queue_trypop(apr_queue_t *queue, void **data) *data = queue->data[queue->out]; queue->nelts--; - queue->out = (queue->out + 1) % queue->bounds; + queue->out++; + if (queue->out >= queue->bounds) + queue->out -= queue->bounds; if (queue->full_waiters) { Q_DBG("signal !full", queue); rv = apr_thread_cond_signal(queue->not_full); |