From afffcaabf6d36966e6d14e44107ed403eebd7479 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Fri, 6 Nov 2015 01:35:26 -0800 Subject: [PATCH] Convert cacheDigestInit to method --- src/CacheDigest.cc | 23 +++++++++++------------ src/CacheDigest.h | 3 +++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/CacheDigest.cc b/src/CacheDigest.cc index ed9700e038..9a5937352d 100644 --- a/src/CacheDigest.cc +++ b/src/CacheDigest.cc @@ -34,18 +34,17 @@ static void cacheDigestHashKey(const CacheDigest * cd, const cache_key * key); /* static array used by cacheDigestHashKey for optimization purposes */ static uint32_t hashed_keys[4]; -static void -cacheDigestInit(CacheDigest * cd, int capacity) +void +CacheDigest::init(int newCapacity) { - const size_t mask_size = CacheDigest::CalcMaskSize(capacity, cd->bits_per_entry); - assert(cd); - assert(capacity > 0 && cd->bits_per_entry > 0); - assert(mask_size > 0); - cd->capacity = capacity; - cd->mask_size = mask_size; - cd->mask = (char *)xcalloc(cd->mask_size, 1); - debugs(70, 2, "cacheDigestInit: capacity: " << cd->capacity << " entries, bpe: " << cd->bits_per_entry << "; size: " - << cd->mask_size << " bytes"); + const auto newMaskSz = CacheDigest::CalcMaskSize(newCapacity, bits_per_entry); + assert(newCapacity > 0 && bits_per_entry > 0); + assert(newMaskSz > 0); + capacity = newCapacity; + mask_size = newMaskSz; + mask = static_cast(xcalloc(mask_size,1)); + debugs(70, 2, "capacity: " << capacity << " entries, bpe: " << bits_per_entry << "; size: " + << mask_size << " bytes"); } CacheDigest::CacheDigest(int aCapacity, int bpe) : @@ -88,7 +87,7 @@ void CacheDigest::updateCapacity(int newCapacity) { safe_free(mask); - cacheDigestInit(this, newCapacity); // will re-init mask and mask_size + init(newCapacity); // will re-init mask and mask_size } bool diff --git a/src/CacheDigest.h b/src/CacheDigest.h index ee5d383b85..68c0b6c490 100644 --- a/src/CacheDigest.h +++ b/src/CacheDigest.h @@ -47,6 +47,9 @@ public: /// a specified capacity and bitsize. static size_t CalcMaskSize(int cap, int bpe); +private: + void init(int newCapacity); + public: /* public, read-only */ char *mask; /* bit mask */ -- 2.47.3