Use QExplicitlySharedDataPointer as the replacement of KSharedPtr
This should be slightly more efficient than the solution from e7e2eedd
which uses QWeakPointer and QSharedPointer
REVIEW: 114932
This commit is contained in:
parent
4235ec4842
commit
afe17f1dca
@ -21,19 +21,20 @@
|
||||
#define PLASMA_SVG_P_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QSharedPointer>
|
||||
#include <QSharedData>
|
||||
#include <QSvgRenderer>
|
||||
#include <QWeakPointer>
|
||||
#include <QExplicitlySharedDataPointer>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Svg;
|
||||
|
||||
class SharedSvgRenderer : public QSvgRenderer
|
||||
class SharedSvgRenderer : public QSvgRenderer, public QSharedData
|
||||
{
|
||||
public:
|
||||
typedef QSharedPointer<SharedSvgRenderer> Ptr;
|
||||
typedef QExplicitlySharedDataPointer<SharedSvgRenderer> Ptr;
|
||||
|
||||
SharedSvgRenderer(QObject *parent = 0);
|
||||
SharedSvgRenderer(
|
||||
const QString &filename,
|
||||
@ -92,7 +93,7 @@ public:
|
||||
void themeChanged();
|
||||
void colorsChanged();
|
||||
|
||||
static QHash<QString, QWeakPointer<SharedSvgRenderer> > s_renderers;
|
||||
static QHash<QString, SharedSvgRenderer::Ptr> s_renderers;
|
||||
static QWeakPointer<Theme> s_systemColorsCache;
|
||||
|
||||
Svg *q;
|
||||
|
@ -418,15 +418,17 @@ void SvgPrivate::createRenderer()
|
||||
QString styleSheet = cacheAndColorsTheme()->d->svgStyleSheet();
|
||||
styleCrc = qChecksum(styleSheet.toUtf8(), styleSheet.size());
|
||||
|
||||
QHash<QString, QWeakPointer<SharedSvgRenderer> >::const_iterator it = s_renderers.constFind(styleCrc + path);
|
||||
QHash<QString, SharedSvgRenderer::Ptr>::const_iterator it = s_renderers.constFind(styleCrc + path);
|
||||
|
||||
renderer = it == s_renderers.constEnd() ? QWeakPointer<SharedSvgRenderer>() : it.value();
|
||||
if (!renderer) {
|
||||
if (it != s_renderers.constEnd()) {
|
||||
//qDebug() << "gots us an existing one!";
|
||||
renderer = it.value();
|
||||
} else {
|
||||
if (path.isEmpty()) {
|
||||
renderer.reset(new SharedSvgRenderer());
|
||||
renderer = new SharedSvgRenderer();
|
||||
} else {
|
||||
QHash<QString, QRectF> interestingElements;
|
||||
renderer.reset(new SharedSvgRenderer(path, styleSheet, interestingElements));
|
||||
renderer = new SharedSvgRenderer(path, styleSheet, interestingElements);
|
||||
|
||||
// Add interesting elements to the theme's rect cache.
|
||||
QHashIterator<QString, QRectF> i(interestingElements);
|
||||
@ -452,15 +454,16 @@ void SvgPrivate::createRenderer()
|
||||
|
||||
void SvgPrivate::eraseRenderer()
|
||||
{
|
||||
if (renderer) {
|
||||
QWeakPointer<SharedSvgRenderer> guard = renderer;
|
||||
renderer.reset();
|
||||
if (guard.isNull() && theme) {
|
||||
// no SvgPrivate instance references this anymore
|
||||
if (renderer && renderer->ref.load() == 2) {
|
||||
// this and the cache reference it
|
||||
s_renderers.erase(s_renderers.find(styleCrc + path));
|
||||
|
||||
if (theme) {
|
||||
theme.data()->releaseRectsCache(path);
|
||||
}
|
||||
}
|
||||
|
||||
renderer = 0;
|
||||
styleCrc = 0;
|
||||
localRectCache.clear();
|
||||
elementsWithSizeHints.clear();
|
||||
@ -642,7 +645,7 @@ void SvgPrivate::colorsChanged()
|
||||
emit q->repaintNeeded();
|
||||
}
|
||||
|
||||
QHash<QString, QWeakPointer<SharedSvgRenderer> > SvgPrivate::s_renderers;
|
||||
QHash<QString, SharedSvgRenderer::Ptr> SvgPrivate::s_renderers;
|
||||
QWeakPointer<Theme> SvgPrivate::s_systemColorsCache;
|
||||
|
||||
Svg::Svg(QObject *parent)
|
||||
|
Loading…
Reference in New Issue
Block a user