From 45e87e05a73be0e35f39daa315d7d3b8dd66803b Mon Sep 17 00:00:00 2001 From: Fushan Wen Date: Mon, 11 Apr 2022 07:25:20 +0800 Subject: [PATCH] wallpapers/image: Port to std::remove_if This should make `ImageBackend::setSlidePaths` slightly more efficient, because a lookup operation in the list is gone. --- wallpapers/image/plugin/imagebackend.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wallpapers/image/plugin/imagebackend.cpp b/wallpapers/image/plugin/imagebackend.cpp index 69dce7d68..ab60f3eb5 100644 --- a/wallpapers/image/plugin/imagebackend.cpp +++ b/wallpapers/image/plugin/imagebackend.cpp @@ -400,12 +400,13 @@ void ImageBackend::setSlidePaths(const QStringList &slidePaths) if (!m_slidePaths.isEmpty()) { // Replace 'preferred://wallpaperlocations' with real paths - const QStringList preProcessedPaths = m_slidePaths; - for (const QString &path : preProcessedPaths) { - if (path == QLatin1String("preferred://wallpaperlocations")) { - m_slidePaths << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("wallpapers"), QStandardPaths::LocateDirectory); - m_slidePaths.removeAll(path); - } + const auto it = std::remove_if(m_slidePaths.begin(), m_slidePaths.end(), [](const QString &path) { + return path == QLatin1String("preferred://wallpaperlocations"); + }); + + if (it != m_slidePaths.end()) { + m_slidePaths.erase(it, m_slidePaths.end()); + m_slidePaths << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("wallpapers"), QStandardPaths::LocateDirectory); } }