diff --git a/src/observersmanager.hpp b/src/observersmanager.hpp index 38a6934..680c571 100644 --- a/src/observersmanager.hpp +++ b/src/observersmanager.hpp @@ -136,9 +136,14 @@ namespace cloonel { m_occupied[parTicket - 1] = false; --m_usedCount; - auto lastNull = std::find(m_occupied.rbegin(), m_occupied.rend(), false); - if (m_occupied.rend() != lastNull) { - const std::size_t newSize = m_occupied.size() - static_cast(lastNull - m_occupied.rbegin()) + 1; + std::size_t deleCount = 0; + for (auto itOcc = m_occupied.rbegin(), itOccEND = m_occupied.rend(); itOcc != itOccEND and not *itOcc; ++itOcc) { + ++deleCount; + } + + if (deleCount) { + assert(deleCount <= m_occupied.size()); + const std::size_t newSize = m_occupied.size() - deleCount; m_occupied.resize(newSize); m_list.resize(newSize); }