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