From: Eduard Bagdasaryan Date: Thu, 28 Jun 2018 17:14:32 +0000 (+0000) Subject: Resume using "Short Strings" memory pool ignored since 91bb468 (#227) X-Git-Tag: M-staged-PR227 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=278e775d0bc4ef20ff285cdd3bc3c38956a823aa;p=thirdparty%2Fsquid.git Resume using "Short Strings" memory pool ignored since 91bb468 (#227) memFindStringSizeType() misused mem_type as a string pool index, resulting in index 0 (of the first pool) mapped to MEM_NONE and ignored. --- diff --git a/src/mem/old_api.cc b/src/mem/old_api.cc index 03bbb863ae..5a260d6d9c 100644 --- a/src/mem/old_api.cc +++ b/src/mem/old_api.cc @@ -113,23 +113,18 @@ GetStrPool(size_t type) return *strPools[type]; } -/* Find the best fit string pool type */ -static mem_type -memFindStringSizeType(size_t net_size, bool fuzzy) +/// \returns the best-fit string pool or nil +static MemAllocator * +memFindStringPool(size_t net_size, bool fuzzy) { - mem_type type = MEM_NONE; for (unsigned int i = 0; i < mem_str_pool_count; ++i) { auto &pool = GetStrPool(i); - if (fuzzy && net_size < pool.objectSize()) { - type = static_cast(i); - break; - } else if (net_size == pool.objectSize()) { - type = static_cast(i); - break; - } + if (fuzzy && net_size < pool.objectSize()) + return &pool; + if (net_size == pool.objectSize()) + return &pool; } - - return type; + return nullptr; } static void @@ -236,14 +231,12 @@ memAllocString(size_t net_size, size_t * gross_size) { assert(gross_size); - auto type = memFindStringSizeType(net_size, true); - if (type != MEM_NONE) { - auto &pool = GetStrPool(type); - *gross_size = pool.objectSize(); + if (const auto pool = memFindStringPool(net_size, true)) { + *gross_size = pool->objectSize(); assert(*gross_size >= net_size); ++StrCountMeter; StrVolumeMeter += *gross_size; - return pool.alloc(); + return pool->alloc(); } *gross_size = net_size; @@ -269,9 +262,8 @@ memFreeString(size_t size, void *buf) { assert(buf); - auto type = memFindStringSizeType(size, false); - if (type != MEM_NONE) - GetStrPool(type).freeOne(buf); + if (const auto pool = memFindStringPool(size, false)) + pool->freeOne(buf); else xfree(buf);