fix a performance issue: add a new insertintocache function, the new
parameter is used to identify pixmaps that shouldn't be inserted in the pixmap cache on disk BUG: 200313 svn path=/trunk/KDE/kdelibs/; revision=1000100
This commit is contained in:
parent
83396186c2
commit
94f3c6a498
@ -621,13 +621,13 @@ void FrameSvgPrivate::cacheFrame(const QString &prefixToSave)
|
||||
|
||||
//kDebug()<<"Saving to cache frame"<<id;
|
||||
|
||||
Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground);
|
||||
Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground, QString::number((int)q)+prefixToSave);
|
||||
|
||||
//insert overlay
|
||||
id = QString::fromLatin1("overlay_%7_%6_%5_%4_%3_%2_%1_").
|
||||
arg(overlayPos.y()).arg(overlayPos.x()).arg(frame->enabledBorders).arg(size.width()).arg(size.height()).arg(prefixToSave).arg(q->imagePath());
|
||||
|
||||
Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground);
|
||||
Theme::defaultTheme()->insertIntoCache(id, frame->cachedBackground, QString::number((int)q)+prefixToSave+"overlay");
|
||||
}
|
||||
|
||||
void FrameSvgPrivate::updateSizes()
|
||||
|
2
svg.cpp
2
svg.cpp
@ -238,7 +238,7 @@ class SvgPrivate
|
||||
}
|
||||
|
||||
if (cacheRendering) {
|
||||
actualTheme()->insertIntoCache(id, p);
|
||||
actualTheme()->insertIntoCache(id, p, QString::number((int)q)+elementId);
|
||||
}
|
||||
|
||||
return p;
|
||||
|
43
theme.cpp
43
theme.cpp
@ -23,6 +23,7 @@
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QTimer>
|
||||
#include <QPair>
|
||||
#ifdef Q_WS_X11
|
||||
#include <QX11Info>
|
||||
#endif
|
||||
@ -152,6 +153,8 @@ public:
|
||||
KSharedConfigPtr svgElementsCache;
|
||||
QHash<QString, QSet<QString> > invalidElements;
|
||||
QHash<QString, QPixmap> pixmapsToCache;
|
||||
QHash<QString, QString> keysToCache;
|
||||
QHash<QString, QString> idsToCache;
|
||||
QTimer *saveTimer;
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
@ -238,16 +241,15 @@ void ThemePrivate::discardCache(bool recreateElementsCache)
|
||||
|
||||
void ThemePrivate::scheduledCacheUpdate()
|
||||
{
|
||||
//kDebug()<< "Saving to cache:";
|
||||
QHash<QString, QPixmap>::const_iterator it = pixmapsToCache.constBegin();
|
||||
|
||||
while (it != pixmapsToCache.constEnd()) {
|
||||
//kDebug()<< "Saving item to cache: " << it.key();
|
||||
pixmapCache->insert(it.key(), it.value());
|
||||
++it;
|
||||
QHashIterator<QString, QPixmap> it(pixmapsToCache);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
pixmapCache->insert(idsToCache[it.key()], it.value());
|
||||
}
|
||||
|
||||
pixmapsToCache.clear();
|
||||
keysToCache.clear();
|
||||
idsToCache.clear();
|
||||
}
|
||||
|
||||
void ThemePrivate::colorsChanged()
|
||||
@ -672,8 +674,13 @@ bool Theme::useNativeWidgetStyle() const
|
||||
bool Theme::findInCache(const QString &key, QPixmap &pix)
|
||||
{
|
||||
if (d->useCache()) {
|
||||
if (d->pixmapsToCache.contains(key)) {
|
||||
pix = d->pixmapsToCache.value(key);
|
||||
if (!d->keysToCache.contains(key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString id = d->keysToCache[key];
|
||||
if (d->pixmapsToCache.contains(id)) {
|
||||
pix = d->pixmapsToCache.value(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -696,8 +703,22 @@ bool Theme::findInCache(const QString &key, QPixmap &pix, unsigned int lastModif
|
||||
void Theme::insertIntoCache(const QString& key, const QPixmap& pix)
|
||||
{
|
||||
if (d->useCache()) {
|
||||
d->pixmapsToCache.insert(key, pix);
|
||||
d->saveTimer->start(500);
|
||||
d->pixmapCache->insert(key, pix);
|
||||
}
|
||||
}
|
||||
|
||||
void Theme::insertIntoCache(const QString& key, const QPixmap& pix, const QString& id)
|
||||
{
|
||||
if (d->useCache()) {
|
||||
d->pixmapsToCache.insert(id, pix);
|
||||
|
||||
if (d->idsToCache.contains(id)) {
|
||||
d->keysToCache.remove(d->idsToCache[id]);
|
||||
}
|
||||
|
||||
d->keysToCache.insert(key, id);
|
||||
d->idsToCache.insert(id, key);
|
||||
d->saveTimer->start(600);
|
||||
}
|
||||
}
|
||||
|
||||
|
17
theme.h
17
theme.h
@ -240,6 +240,23 @@ class PLASMA_EXPORT Theme : public QObject
|
||||
**/
|
||||
void insertIntoCache(const QString& key, const QPixmap& pix);
|
||||
|
||||
/**
|
||||
* Insert specified pixmap into the cache.
|
||||
* If the cache already contains pixmap with the specified key then it is
|
||||
* overwritten.
|
||||
* The actual insert is delayed for optimization reasons and the id
|
||||
* parameter is used to discard repeated inserts in the delay time, useful
|
||||
* when for instance the graphics to inser comes from a quickly resizing
|
||||
* object: the frames between the start and destination sizes aren't
|
||||
* useful in the cache and just cause overhead.
|
||||
*
|
||||
* @param key the name to use in the cache for this pixmap
|
||||
* @param pix the pixmap data to store in the cache
|
||||
* @param id a name that identifies the caller class of this function in an unique fashion
|
||||
* @since 4.3
|
||||
**/
|
||||
void insertIntoCache(const QString& key, const QPixmap& pix, const QString& id);
|
||||
|
||||
/**
|
||||
* Sets the maximum size of the cache (in kilobytes). If cache gets bigger
|
||||
* the limit then some entries are removed
|
||||
|
Loading…
Reference in New Issue
Block a user