pool: ensure indices are pushed low to high

This commit is contained in:
Danny Robson 2019-05-24 11:31:44 +10:00
parent 25a74badd6
commit ad9d5d991c

View File

@ -74,9 +74,7 @@ namespace cruft {
if (!m_store)
throw std::bad_alloc ();
T* elements = reinterpret_cast<T*> (m_store);
for (size_t i = 0; i < m_capacity; ++i)
m_available.push (elements + i);
reindex ();
}
@ -190,10 +188,7 @@ namespace cruft {
++data_cursor;
}
m_available.clear ();
T* elements = reinterpret_cast<T*> (m_store);
for (size_t i = 0; i < m_capacity; ++i)
m_available.push (elements + i);
reindex ();
}
@ -231,5 +226,15 @@ namespace cruft {
{
return reinterpret_cast<T*> (m_store) [idx];
}
private:
void reindex (void)
{
m_available.clear ();
T* elements = reinterpret_cast<T*> (m_store);
for (size_t i = m_capacity; i--; )
m_available.push (elements + i);
}
};
}