diff --git a/AK/Queue.h b/AK/Queue.h index d52026f107f..c87750a8792 100644 --- a/AK/Queue.h +++ b/AK/Queue.h @@ -46,6 +46,13 @@ public: m_index_into_first = 0; } --m_size; + if (m_size == 0 && !m_segments.is_empty()) { + // This is not necessary for correctness but avoids faulting in + // all the pages for the underlying Vector in the case where + // the caller repeatedly enqueues and then dequeues a single item. + m_index_into_first = 0; + m_segments.last()->data.clear_with_capacity(); + } return value; }