From f2382990742bff816ec54883e6204ededc378e7f Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Thu, 6 Aug 2026 21:09:57 -1000 Subject: Settle the names, types and layout of the sources --- source/cache.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'source/cache.c') diff --git a/source/cache.c b/source/cache.c index aff0f4d..105ecfe 100644 --- a/source/cache.c +++ b/source/cache.c @@ -21,6 +21,12 @@ #endif #define CACHE_BUFSIZE (1024 * 4) +/* Crude implementation of 32-bit FNV-1 hash algorithm, + * see http://www.isthe.com/chongo/tech/comp/fnv/ for details + * about the magic numbers. + */ +#define FNV_OFFSET 0x811c9dc5 +#define FNV_PRIME 0x01000193 struct cache_slot { const char *key; @@ -63,7 +69,7 @@ static int open_slot(struct cache_slot *slot) bufkeylen = bufz - slot->buf; if (slot->key) - slot->match = bufkeylen == slot->keylen && + slot->match = bufkeylen >= 0 && (size_t)bufkeylen == slot->keylen && !memcmp(slot->key, slot->buf, bufkeylen + 1); return 0; @@ -246,14 +252,7 @@ static int fill_slot(struct cache_slot *slot) return 0; } -/* Crude implementation of 32-bit FNV-1 hash algorithm, - * see http://www.isthe.com/chongo/tech/comp/fnv/ for details - * about the magic numbers. - */ -#define FNV_OFFSET 0x811c9dc5 -#define FNV_PRIME 0x01000193 - -unsigned long hash_str(const char *str) +unsigned long cache_hash_str(const char *str) { unsigned long h = FNV_OFFSET; unsigned char *s = (unsigned char *)str; @@ -379,7 +378,7 @@ int cache_process(int size, const char *path, const char *key, int ttl, } if (!key) key = ""; - hash = hash_str(key) % size; + hash = cache_hash_str(key) % size; strbuf_addstr(&filename, path); strbuf_ensure_end(&filename, '/'); for (i = 0; i < 8; i++) { -- cgit v2.8.0