From: Claudio Cambra Date: Thu, 17 Oct 2024 06:48:58 +0000 (+0800) Subject: Store duplicate indices as key-value pair with value storing bucket of all duplicates X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~58^2^2~102^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=cd1d1f583328fdac494dea8a4e8980c62fe78ea5;p=nextcloud-desktop.git Store duplicate indices as key-value pair with value storing bucket of all duplicates Signed-off-by: Claudio Cambra --- 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