hi.. since reviewboard is not accepting my diff to plasma-mobile (either from the website or via the usual post-review; it seems to think there is no components/mobilecomponents/fallbackcomponent.cpp file... :/) i'm posting a patch here that implements some basic caching to avoid hitting disk more often than necessary. it uses QCache so as to prevent unlimited memory usage.
also, this seems to be the only thing from the plasma-mobile repository that SLC now uses. since it is so trivial, i'm considering just copying it into SLC wholesale. the only other thing that uses FallbackComponent is the ResourceDelegate that is used extensively in plasma-mobile, so the functionality of FallbackComponent is indeed needed, though i wonder if it needs to be its own entire componet just to access that one small bit of code. might be nicer if it were it were just part of ResourceDelegate .. but that's pure QML so probably not possible. anyways ... patch and SLC usage -> thoughts? -- Aaron J. Seigo
diff --git a/components/mobilecomponents/fallbackcomponent.cpp b/components/mobilecomponents/fallbackcomponent.cpp index 33fa820..10fb0a6 100644 --- a/components/mobilecomponents/fallbackcomponent.cpp +++ b/components/mobilecomponents/fallbackcomponent.cpp @@ -34,16 +34,27 @@ FallbackComponent::FallbackComponent(QObject *parent) QString FallbackComponent::resolvePath(const QString &component, const QStringList &paths) { + QString resolved; foreach (const QString &path, paths) { //kDebug() << "Searching for" << path; - //TODO: cache this, to prevent too much disk access - const QString resolved = KStandardDirs::locate("data", "plasma/" + component + '/' + path); + const QString key = component + '/' + path; + if (m_paths.contains(key)) { + resolved = *m_paths.object(key); + if (!resolved.isEmpty()) { + break; + } else { + continue; + } + } + + resolved = KStandardDirs::locate("data", "plasma/" + key); + m_paths.insert(key, new QString(resolved)); if (!resolved.isEmpty()) { - return resolved; + break; } } - return QString(); + return resolved; } #include "fallbackcomponent.moc" diff --git a/components/mobilecomponents/fallbackcomponent.h b/components/mobilecomponents/fallbackcomponent.h index 4bf98b2..b5a13fa 100644 --- a/components/mobilecomponents/fallbackcomponent.h +++ b/components/mobilecomponents/fallbackcomponent.h @@ -22,6 +22,7 @@ #include <QObject> +#include <QCache> class FallbackComponent : public QObject @@ -32,6 +33,9 @@ public: FallbackComponent(QObject *parent = 0); Q_INVOKABLE QString resolvePath(const QString &component, const QStringList &paths); + +private: + QCache<QString, QString> m_paths; }; #endif
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel