From 027a50abe9f84c833994a35c428d22262a0698b7 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sat, 31 Oct 2026 11:47:09 +0100 Subject: fix: keep undo bookkeeping linear on large writes addChangedMessageIds() ran QStringList::contains per id, quadratic on a 10k-message write, which item 211's archive and item 212's backfill both produce. Co-Authored-By: Claude Opus 5.5 --- src/mainwindow.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/mainwindow.h b/src/mainwindow.h index 868964a..45d9288 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -2172,9 +2172,13 @@ public: /// redo of a batch arrives as more than one confirmation. void addChangedMessageIds(const QStringList &ids) { + // A set beside the list, so a 10k-message write is not quadratic + // here (items 211, 212). The list keeps the order for the undo. for (const QString &id : ids) { - if (!m_changedMessageIds.contains(id)) + if (!m_seen.contains(id)) { + m_seen.insert(id); m_changedMessageIds.append(id); + } } } @@ -2183,10 +2187,15 @@ public: protected: /// Cleared before each re-send, so a redo learns what IT moved rather than /// undoing the effect of the run before it. - void forgetChangedMessageIds() { m_changedMessageIds.clear(); } + void forgetChangedMessageIds() + { + m_changedMessageIds.clear(); + m_seen.clear(); + } private: QStringList m_changedMessageIds; + QSet m_seen; }; /// Undo entry for a tag change over a set of threads. -- cgit v1.2.3