From 10ff7dddbd4e8c2b81832d406ed99a57ccf7eae0 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 17 Oct 2024 14:48:58 +0800 Subject: [PATCH] Store duplicate indices as key-value pair with value storing bucket of all duplicates Signed-off-by: Claudio Cambra --- src/gui/filedetails/sharemodel.cpp | 21 +++++++++++---------- src/gui/filedetails/sharemodel.h | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/gui/filedetails/sharemodel.cpp b/src/gui/filedetails/sharemodel.cpp index c864993f9..23f03edf2 100644 --- a/src/gui/filedetails/sharemodel.cpp +++ b/src/gui/filedetails/sharemodel.cpp @@ -501,23 +501,24 @@ void ShareModel::slotSharesFetched(const QList &shares) continue; } - auto hasDuplicates = false; + const auto duplicateIndices = QSharedPointer>::create(); + const auto handleDuplicateIndex = [this, duplicateIndices](const unsigned int idx) { + duplicateIndices->insert(idx); + _duplicateDisplayNameShareIndices[idx] = duplicateIndices; + const auto targetIdx = index(idx); + dataChanged(targetIdx, targetIdx, {Qt::DisplayRole}); + }; + for (auto j = i + 1; j < shareCount; ++j) { const auto otherSharee = _shares.at(j)->getShareWith(); if (otherSharee == nullptr || sharee->format() != otherSharee->format()) { continue; } - - hasDuplicates = true; // Reassign is faster - _duplicateDisplayNameShareIndices.insert(j); - const auto targetIndex = index(j); - dataChanged(targetIndex, targetIndex, {Qt::DisplayRole}); + handleDuplicateIndex(j); } - if (hasDuplicates) { - _duplicateDisplayNameShareIndices.insert(i); - const auto targetIndex = index(i); - dataChanged(targetIndex, targetIndex, {Qt::DisplayRole}); + if (!duplicateIndices->isEmpty()) { + handleDuplicateIndex(i); } } diff --git a/src/gui/filedetails/sharemodel.h b/src/gui/filedetails/sharemodel.h index 7fe218717..09d136f1e 100644 --- a/src/gui/filedetails/sharemodel.h +++ b/src/gui/filedetails/sharemodel.h @@ -253,7 +253,8 @@ private: QHash _shareIdIndexHash; QHash _shareIdRecentlySetPasswords; QVector _sharees; - QSet _duplicateDisplayNameShareIndices; + // Buckets of sharees with the same display name + QHash>> _duplicateDisplayNameShareIndices; }; } // namespace OCC