mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
[FileItemRolesUpdater] Use STL-style iterator instead of iterating a copy
QSet<T>::erase(it) is the save way of erasing from a QSet while iterating it. This saves creating a copy of the QSet, lookup of a node by value in `QSet<T>::remove(item)`, and repeated rehashing caused by `remove`.
This commit is contained in:
parent
7c0b5c08cc
commit
492cfb73a3
|
@ -957,15 +957,17 @@ void KFileItemModelRolesUpdater::updateChangedItems()
|
|||
visibleChangedIndexes.reserve(m_changedItems.size());
|
||||
invisibleChangedIndexes.reserve(m_changedItems.size());
|
||||
|
||||
// Iterate over a const copy because items are deleted within the loop
|
||||
const auto changedItems = m_changedItems;
|
||||
for (const KFileItem &item : changedItems) {
|
||||
auto oldsize = m_changedItems.size();
|
||||
auto changedItemsIt = m_changedItems.begin();
|
||||
while (changedItemsIt != m_changedItems.end()) {
|
||||
const auto& item = *changedItemsIt;
|
||||
const int index = m_model->index(item);
|
||||
|
||||
if (index < 0) {
|
||||
m_changedItems.remove(item);
|
||||
changedItemsIt = m_changedItems.erase(changedItemsIt);
|
||||
continue;
|
||||
}
|
||||
++changedItemsIt;
|
||||
|
||||
if (index >= m_firstVisibleIndex && index <= m_lastVisibleIndex) {
|
||||
visibleChangedIndexes.append(index);
|
||||
|
|
Loading…
Reference in a new issue