Commit a4de7bf6 authored by Fushan Wen's avatar Fushan Wen
Browse files

wallpapers/image: reduce preview cache insertion for single images

This reduces one cache insertion operation for single images without
dark variants by inserting a new QPixmap only when the pending list
is empty (it->empty()), which should slightly reduce the time to
generate previews.


(cherry picked from commit 7164c1ac)
parent a8854e01
Pipeline #243190 passed with stage
in 8 minutes and 8 seconds
......@@ -81,12 +81,12 @@ void AbstractImageListModel::slotHandlePreview(const KFileItem &item, const QPix
it->removeOne(urlString);
const QStringList paths = job->property("paths").toStringList();
QPixmap *cachedPreview = m_imageCache.object(paths);
QPixmap *const cachedPreview = m_imageCache.object(paths);
if (!cachedPreview) {
// Insert full preview
if (!cachedPreview && !it->empty()) {
m_imageCache.insert(paths, new QPixmap(preview), 0);
} else {
// it->empty() is handled in the end
} else if (cachedPreview) {
// Show multiple images side by side
QPainter p(cachedPreview);
......@@ -107,8 +107,12 @@ void AbstractImageListModel::slotHandlePreview(const KFileItem &item, const QPix
// All images in the list have been loaded
m_previewJobsUrls.erase(it);
cachedPreview = m_imageCache.object(paths);
auto finalPreview = new QPixmap(*cachedPreview);
QPixmap *finalPreview = nullptr;
if (!cachedPreview) {
finalPreview = new QPixmap(preview);
} else {
finalPreview = new QPixmap(*cachedPreview);
}
if (m_imageCache.insert(paths, finalPreview, 1)) {
Q_EMIT dataChanged(idx, idx, {ScreenshotRole});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment