From 169beff21ef85e57da23fc870fd4e8b937e10ef3 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 30 Nov 2020 09:59:14 +0330 Subject: [PATCH] LibGUI: Add a ModelSelection::add_all(Vector) API Using add() is very slow due to the change notifications. --- Libraries/LibGUI/ModelSelection.cpp | 12 ++++++++++++ Libraries/LibGUI/ModelSelection.h | 1 + 2 files changed, 13 insertions(+) diff --git a/Libraries/LibGUI/ModelSelection.cpp b/Libraries/LibGUI/ModelSelection.cpp index 5b4d208883..2a22336855 100644 --- a/Libraries/LibGUI/ModelSelection.cpp +++ b/Libraries/LibGUI/ModelSelection.cpp @@ -64,6 +64,18 @@ void ModelSelection::add(const ModelIndex& index) notify_selection_changed(); } +void ModelSelection::add_all(const Vector& indices) +{ + { + TemporaryChange notify_change { m_disable_notify, true }; + for (auto& index : indices) + add(index); + } + + if (m_notify_pending) + notify_selection_changed(); +} + void ModelSelection::toggle(const ModelIndex& index) { ASSERT(index.is_valid()); diff --git a/Libraries/LibGUI/ModelSelection.h b/Libraries/LibGUI/ModelSelection.h index d40cea4a36..78e0585250 100644 --- a/Libraries/LibGUI/ModelSelection.h +++ b/Libraries/LibGUI/ModelSelection.h @@ -59,6 +59,7 @@ public: void set(const ModelIndex&); void add(const ModelIndex&); + void add_all(const Vector&); void toggle(const ModelIndex&); bool remove(const ModelIndex&); void clear();