]> granicus.if.org Git - apache/commitdiff
Strength-reduce a 64-bit "mod 16" operation to "& 0xf" in cached_explode()
authorBrian Pane <brianp@apache.org>
Thu, 11 Jul 2002 16:08:58 +0000 (16:08 +0000)
committerBrian Pane <brianp@apache.org>
Thu, 11 Jul 2002 16:08:58 +0000 (16:08 +0000)
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
server/util_time.c

index 00cacf6cf548681aba3cdc35562216cc041be395..b4374878b5d39ca4f1788db066f732cbac073f9f 100644 (file)
@@ -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
 
index 7b8447f5dbba841d55b64e5d1ba07a5933e08e43..35f9d7dc898529505e70a64aa90f991d098c2fac 100644 (file)
@@ -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,