From: Amos Jeffries Date: Thu, 5 Nov 2015 16:58:09 +0000 (-0800) Subject: Make cacheDigestChangeCap() a method X-Git-Tag: SQUID_4_0_3~18^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7daad00cd43e2e233e6f51a7d12b42af94a5707d;p=thirdparty%2Fsquid.git Make cacheDigestChangeCap() a method * Rename to updateCapacity(int) * Also, use updateCapacity() instead of *Init() to construct the digest --- diff --git a/src/CacheDigest.cc b/src/CacheDigest.cc index 7ddb78c900..7b59c64eae 100644 --- a/src/CacheDigest.cc +++ b/src/CacheDigest.cc @@ -53,12 +53,12 @@ CacheDigest::CacheDigest(int aCapacity, int bpe) : mask(nullptr), mask_size(0), capacity(0), - bits_per_entry(0), + bits_per_entry(bpe), count(0), del_count(0) { assert(SQUID_MD5_DIGEST_LENGTH == 16); /* our hash functions rely on 16 byte keys */ - cacheDigestInit(this, aCapacity, bpe); + updateCapacity(aCapacity); } CacheDigest::~CacheDigest() @@ -85,13 +85,11 @@ CacheDigest::clear() memset(mask, 0, mask_size); } -/* changes mask size, resets bits to 0, preserves "cd" pointer */ void -cacheDigestChangeCap(CacheDigest * cd, int new_cap) +CacheDigest::updateCapacity(int newCapacity) { - assert(cd); - safe_free(cd->mask); - cacheDigestInit(cd, new_cap, cd->bits_per_entry); // will re-init mask and mask_size + safe_free(mask); + cacheDigestInit(this, newCapacity, bits_per_entry); // will re-init mask and mask_size } /* returns true if the key belongs to the digest */ diff --git a/src/CacheDigest.h b/src/CacheDigest.h index 35da804697..2e3ad3197c 100644 --- a/src/CacheDigest.h +++ b/src/CacheDigest.h @@ -31,6 +31,9 @@ public: /// reset the digest mask and counters void clear(); + /// changes mask size to fit newCapacity, resets bits to 0 + void updateCapacity(int newCapacity); + public: /* public, read-only */ char *mask; /* bit mask */ @@ -41,7 +44,6 @@ public: int del_count; /* number of deletions performed so far */ }; -void cacheDigestChangeCap(CacheDigest * cd, int new_cap); int cacheDigestTest(const CacheDigest * cd, const cache_key * key); void cacheDigestAdd(CacheDigest * cd, const cache_key * key); void cacheDigestDel(CacheDigest * cd, const cache_key * key); diff --git a/src/store_digest.cc b/src/store_digest.cc index 07d07ca7c7..fe048e192a 100644 --- a/src/store_digest.cc +++ b/src/store_digest.cc @@ -518,7 +518,7 @@ storeDigestResize(void) return 0; } else { debugs(71, 2, "storeDigestResize: big change, resizing."); - cacheDigestChangeCap(store_digest, cap); + store_digest->updateCapacity(cap); return 1; } } diff --git a/src/tests/stub_CacheDigest.cc b/src/tests/stub_CacheDigest.cc index 316f0b5075..f305e22c5c 100644 --- a/src/tests/stub_CacheDigest.cc +++ b/src/tests/stub_CacheDigest.cc @@ -21,7 +21,7 @@ CacheDigest::CacheDigest(int, int) {STUB} CacheDigest::~CacheDigest() {STUB} CacheDigest *CacheDigest::clone() const STUB_RETVAL(nullptr) void CacheDigest::clear() STUB -void cacheDigestChangeCap(CacheDigest *,int) STUB +void CacheDigest::updateCapacity(int) STUB int cacheDigestTest(const CacheDigest *, const cache_key *) STUB_RETVAL(1) void cacheDigestAdd(CacheDigest *, const cache_key *) STUB void cacheDigestDel(CacheDigest *, const cache_key *) STUB