cvs: pecl /apc apc_cache.c
| From: | Sterling Hughes | Date: | Thu, 26 Jun 2003 08:48:00 +0000 |
| Subject: | cvs: pecl /apc apc_cache.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-314@lists.php.net to get a copy of this message | ||
sterling Thu Jun 26 04:48:00 2003 EDT
Modified files:
/pecl/apc apc_cache.c
Log:
go halfway. Use & and a table mask which is signifigantly faster than '%'
but don't remove the extra level of indirection.
Index: pecl/apc/apc_cache.c
diff -u pecl/apc/apc_cache.c:3.45 pecl/apc/apc_cache.c:3.46
--- pecl/apc/apc_cache.c:3.45 Thu Jun 26 04:03:06 2003
+++ pecl/apc/apc_cache.c Thu Jun 26 04:48:00 2003
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: apc_cache.c,v 3.45 2003/06/26 08:03:06 gschlossnagle Exp $ */
+/* $Id: apc_cache.c,v 3.46 2003/06/26 08:48:00 sterling Exp $ */
#include "apc_cache.h"
#include "apc_sem.h"
@@ -57,6 +57,7 @@
header_t* header; /* cache header (stored in SHM) */
slot_t** slots; /* array of cache slots (stored in SHM) */
int num_slots; /* number of slots in cache */
+ int mask; /* Mask to find necessary slot */
int gc_ttl; /* maximum time on GC list for a slot */
int lock; /* global semaphore lock */
};
@@ -201,6 +202,7 @@
cache->slots = (slot_t**) (((char*) cache->shmaddr) + sizeof(header_t));
cache->num_slots = num_slots;
+ cache->mask = 1 << num_slots;
cache->gc_ttl = gc_ttl;
cache->lock = CREATE_LOCK;
@@ -256,7 +258,7 @@
LOCK(cache);
process_pending_removals(cache);
- slot = &cache->slots[hash(key) % cache->num_slots];
+ slot = &cache->slots[hash(key) & cache->mask];
while (*slot) {
if (key_equals((*slot)->key, key)) {
if ((*slot)->key.mtime < key.mtime) {
@@ -286,7 +288,7 @@
LOCK(cache);
- slot = &cache->slots[hash(key) % cache->num_slots];
+ slot = &cache->slots[hash(key) & cache->mask];
while (*slot) {
if (key_equals((*slot)->key, key)) {
if ((*slot)->key.mtime < key.mtime) {