cvs: pecl /apc apc_cache.c

From: Date: Thu, 26 Jun 2003 07:57:56 +0000
Subject: cvs: pecl /apc apc_cache.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-311@lists.php.net to get a copy of this message
sterling Thu Jun 26 03:57:56 2003 EDT Modified files: /pecl/apc apc_cache.c Log: optimize the hash in a few places really only attack the find() code, as that's where we spend our time Index: pecl/apc/apc_cache.c diff -u pecl/apc/apc_cache.c:3.43 pecl/apc/apc_cache.c:3.44 --- pecl/apc/apc_cache.c:3.43 Sat Jun 14 00:29:00 2003 +++ pecl/apc/apc_cache.c Thu Jun 26 03:57:56 2003 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: apc_cache.c,v 3.43 2003/06/14 04:29:00 gschlossnagle Exp $ */ +/* $Id: apc_cache.c,v 3.44 2003/06/26 07:57:56 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 the current 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) { @@ -282,27 +284,27 @@ /* {{{ apc_cache_find */ apc_cache_entry_t* apc_cache_find(apc_cache_t* cache, apc_cache_key_t key) { - slot_t** slot; - - LOCK(cache); - - slot = &cache->slots[hash(key) % cache->num_slots]; - while (*slot) { - if (key_equals((*slot)->key, key)) { - if ((*slot)->key.mtime < key.mtime) { - remove_slot(cache, slot); + slot_t* slot; + + LOCK(cache); + + slot = cache->slots[hash(key) & cache->mask]; + while (slot) { + if (key_equals(slot->key, key)) { + if (slot->key.mtime != key.mtime) { + remove_slot(cache, &cache->slots[hash(key) & cache->mask]); break; } - (*slot)->num_hits++; - (*slot)->value->ref_count++; - prevent_garbage_collection((*slot)->value); + slot->num_hits++; + slot->value->ref_count++; + prevent_garbage_collection(slot->value); cache->header->num_hits++; UNLOCK(cache); - return (*slot)->value; + return slot->value; } - slot = &(*slot)->next; + slot = slot->next; } cache->header->num_misses++;

« previous php.pecl.cvs (#311) next »