From 97b9c76435b138fb4be0f6dce8f8224e989a685d Mon Sep 17 00:00:00 2001 From: Brian Pane Date: Thu, 11 Jul 2002 16:08:58 +0000 Subject: [PATCH] Strength-reduce a 64-bit "mod 16" operation to "& 0xf" in cached_explode() just in case the compiler doesn't do it for us git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96012 13f79535-47bb-0310-9956-ffa450edef68 --- include/util_time.h | 1 + server/util_time.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/util_time.h b/include/util_time.h index 00cacf6cf5..b4374878b5 100644 --- a/include/util_time.h +++ b/include/util_time.h @@ -70,6 +70,7 @@ extern "C" { /* Maximum delta from the current time, in seconds, for a past time * to qualify as "recent" for use in the ap_explode_recent_*() functions: + * (Must be a power of two minus one!) */ #define AP_TIME_RECENT_THRESHOLD 15 diff --git a/server/util_time.c b/server/util_time.c index 7b8447f5db..35f9d7dc89 100644 --- a/server/util_time.c +++ b/server/util_time.c @@ -67,6 +67,14 @@ struct exploded_time_cache_element { /* the "+ 1" is for the current second: */ #define TIME_CACHE_SIZE (AP_TIME_RECENT_THRESHOLD + 1) +/* Note that AP_TIME_RECENT_THRESHOLD is defined to + * be a power of two minus one in util_time.h, so that + * we can replace a modulo operation with a bitwise AND + * when hashing items into a cache of size + * AP_TIME_RECENT_THRESHOLD+1 + */ +#define TIME_CACHE_MASK (AP_TIME_RECENT_THRESHOLD) + static struct exploded_time_cache_element exploded_cache_localtime[TIME_CACHE_SIZE]; static struct exploded_time_cache_element exploded_cache_gmt[TIME_CACHE_SIZE]; @@ -77,7 +85,7 @@ static apr_status_t cached_explode(apr_time_exp_t *xt, apr_time_t t, { apr_int64_t seconds = apr_time_sec(t); struct exploded_time_cache_element *cache_element = - &(cache[seconds % TIME_CACHE_SIZE]); + &(cache[seconds & TIME_CACHE_MASK]); struct exploded_time_cache_element cache_element_snapshot; /* The cache is implemented as a ring buffer. Each second, -- 2.40.0