Commit 45cf4ef0 authored by Peter Bell's avatar Peter Bell
Browse files

Address review comments

parent 7bcf9796
......@@ -2268,23 +2268,19 @@ template<typename T> shared_ptr<T> get_plan(size_t length)
{
constexpr size_t nmax=10;
static array<shared_ptr<T>, nmax> cache;
static array<unsigned, nmax> last_access{{0}};
static unsigned access_counter = 0;
static array<size_t, nmax> last_access{{0}};
static size_t access_counter = 0;
static mutex mut;
auto find_in_cache = [&]() -> shared_ptr<T>
{
// Guard against overflow
if (access_counter == UINT_MAX)
{
access_counter = 0;
last_access.fill(0);
}
for (size_t i=0; i<nmax; ++i)
if (cache[i] && (cache[i]->length()==length))
{
last_access[i] = access_counter++;
// Guard against overflow
if (access_counter == 0)
last_access.fill(0);
return cache[i];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment