Add a Vector::clear_with_capacity() that doesn't release the backing store.

Use this for WindowManager's dirty rects to avoid kmalloc traffic.
This commit is contained in:
Andreas Kling 2019-01-12 07:22:25 +01:00
parent b7d83e3265
commit 8068b8e09e
2 changed files with 15 additions and 3 deletions

View file

@ -100,6 +100,15 @@ public:
m_impl = nullptr;
}
void clear_with_capacity()
{
if (!m_impl)
return;
for (size_t i = 0; i < size(); ++i)
at(i).~T();
m_impl->m_size = 0;
}
bool contains_slow(const T& value) const
{
for (size_t i = 0; i < size(); ++i) {

View file

@ -223,6 +223,9 @@ void WindowManager::processMouseEvent(MouseEvent& event)
void WindowManager::compose()
{
printf("[WM] compose #%u (%u rects)\n", ++m_recompose_count, m_invalidated_rects.size());
dbgprintf("kmalloc stats: alloc:%u free:%u eternal:%u\n", sum_alloc, sum_free, kmalloc_sum_eternal);
auto any_window_contains_rect = [this] (const Rect& r) {
for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
if (outerRectForWindow(window->rect()).contains(r))
@ -235,7 +238,7 @@ void WindowManager::compose()
for (auto& r : m_invalidated_rects) {
if (any_window_contains_rect(r))
continue;
dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height());
//dbgprintf("Repaint root %d,%d %dx%d\n", r.x(), r.y(), r.width(), r.height());
painter.fillRect(r, Color(0, 72, 96));
}
}
@ -249,7 +252,7 @@ void WindowManager::compose()
for (auto& r : m_invalidated_rects) {
flush(r);
}
m_invalidated_rects.clear();
m_invalidated_rects.clear_with_capacity();
}
void WindowManager::redraw_cursor()
@ -311,7 +314,7 @@ bool WindowManager::isVisible(Window& window) const
void WindowManager::invalidate()
{
m_invalidated_rects.clear();
m_invalidated_rects.clear_with_capacity();
m_invalidated_rects.append(AbstractScreen::the().rect());
}