diff options
| author | Frank Reininghaus <[email protected]> | 2014-01-06 20:10:08 +0100 |
|---|---|---|
| committer | Frank Reininghaus <[email protected]> | 2014-01-06 20:10:08 +0100 |
| commit | 24ad08714e80fab29b4679c0c50e3616f2b5db54 (patch) | |
| tree | a782d97cdc05eff73c39518b76e8b8a8e916273b /src/kitemviews | |
| parent | 4ddc3cfdde7a52f5880928f7cc8ee8896ded686d (diff) | |
Avoid calling KFileItemModel::index() in KFileItemModelRolesUpdater
KFileItemModel allows to find out the index of a KFileItem with its
index(const KFileItem&) method. Calling this method is not extremely
expensive, but it's also not free (it looks up the URL of the KFileItem
in a QHash, i.e., it has to call qHash(QString) for the full URL).
In KFileItemModelRolesUpdater, we sometimes converted the known index to
a KFileItem and then back to an index in applyResolvedRoles(KFileItem).
This patch fixes this by modifying applyResolvedRoles such that it takes
the index directly as its argument.
REVIEW: 114847
Diffstat (limited to 'src/kitemviews')
| -rw-r--r-- | src/kitemviews/kfileitemmodelrolesupdater.cpp | 22 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemmodelrolesupdater.h | 2 |
2 files changed, 8 insertions, 16 deletions
diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp index d6445c981..f11d5a5d3 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -587,7 +587,7 @@ void KFileItemModelRolesUpdater::slotPreviewFailed(const KFileItem& item) connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)), this, SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>))); - applyResolvedRoles(item, ResolveAll); + applyResolvedRoles(index, ResolveAll); m_finishedItems.insert(item); } } @@ -664,7 +664,7 @@ void KFileItemModelRolesUpdater::resolveNextPendingRoles() continue; } - applyResolvedRoles(item, ResolveAll); + applyResolvedRoles(index, ResolveAll); m_finishedItems.insert(item); m_changedItems.remove(item); break; @@ -850,8 +850,7 @@ void KFileItemModelRolesUpdater::updateVisibleIcons() // Try to determine the final icons for all visible items. int index; for (index = m_firstVisibleIndex; index <= lastVisibleIndex && timer.elapsed() < MaxBlockTimeout; ++index) { - const KFileItem item = m_model->fileItem(index); - applyResolvedRoles(item, ResolveFast); + applyResolvedRoles(index, ResolveFast); } // KFileItemListView::initializeItemListWidget(KItemListWidget*) will load @@ -1024,27 +1023,20 @@ void KFileItemModelRolesUpdater::applySortProgressToModel() m_model->emitSortProgress(resolvedCount); } -bool KFileItemModelRolesUpdater::applyResolvedRoles(const KFileItem& item, ResolveHint hint) +bool KFileItemModelRolesUpdater::applyResolvedRoles(int index, ResolveHint hint) { - if (item.isNull()) { - return false; - } - + const KFileItem item = m_model->fileItem(index); const bool resolveAll = (hint == ResolveAll); bool iconChanged = false; if (!item.isMimeTypeKnown() || !item.isFinalIconKnown()) { item.determineMimeType(); iconChanged = true; - } else { - const int index = m_model->index(item); - if (!m_model->data(index).contains("iconName")) { - iconChanged = true; - } + } else if (!m_model->data(index).contains("iconName")) { + iconChanged = true; } if (iconChanged || resolveAll || m_clearPreviews) { - const int index = m_model->index(item); if (index < 0) { return false; } diff --git a/src/kitemviews/kfileitemmodelrolesupdater.h b/src/kitemviews/kfileitemmodelrolesupdater.h index fced44a85..19207575e 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.h +++ b/src/kitemviews/kfileitemmodelrolesupdater.h @@ -261,7 +261,7 @@ private: ResolveFast, ResolveAll }; - bool applyResolvedRoles(const KFileItem& item, ResolveHint hint); + bool applyResolvedRoles(int index, ResolveHint hint); QHash<QByteArray, QVariant> rolesData(const KFileItem& item); /** |
