From afe17f1dca77ac6afd0f176469bb8e86e010c17c Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Tue, 14 Jan 2014 19:41:04 +0100 Subject: [PATCH] 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 --- src/plasma/private/svg_p.h | 11 ++++++----- src/plasma/svg.cpp | 25 ++++++++++++++----------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/plasma/private/svg_p.h b/src/plasma/private/svg_p.h index 16ed29638..332efda6f 100644 --- a/src/plasma/private/svg_p.h +++ b/src/plasma/private/svg_p.h @@ -21,19 +21,20 @@ #define PLASMA_SVG_P_H #include -#include +#include #include -#include +#include namespace Plasma { class Svg; -class SharedSvgRenderer : public QSvgRenderer +class SharedSvgRenderer : public QSvgRenderer, public QSharedData { public: - typedef QSharedPointer Ptr; + typedef QExplicitlySharedDataPointer Ptr; + SharedSvgRenderer(QObject *parent = 0); SharedSvgRenderer( const QString &filename, @@ -92,7 +93,7 @@ public: void themeChanged(); void colorsChanged(); - static QHash > s_renderers; + static QHash s_renderers; static QWeakPointer s_systemColorsCache; Svg *q; diff --git a/src/plasma/svg.cpp b/src/plasma/svg.cpp index ae9778330..c487a64fd 100644 --- a/src/plasma/svg.cpp +++ b/src/plasma/svg.cpp @@ -418,15 +418,17 @@ void SvgPrivate::createRenderer() QString styleSheet = cacheAndColorsTheme()->d->svgStyleSheet(); styleCrc = qChecksum(styleSheet.toUtf8(), styleSheet.size()); - QHash >::const_iterator it = s_renderers.constFind(styleCrc + path); + QHash::const_iterator it = s_renderers.constFind(styleCrc + path); - renderer = it == s_renderers.constEnd() ? QWeakPointer() : 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 interestingElements; - renderer.reset(new SharedSvgRenderer(path, styleSheet, interestingElements)); + renderer = new SharedSvgRenderer(path, styleSheet, interestingElements); // Add interesting elements to the theme's rect cache. QHashIterator i(interestingElements); @@ -452,15 +454,16 @@ void SvgPrivate::createRenderer() void SvgPrivate::eraseRenderer() { - if (renderer) { - QWeakPointer 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 > SvgPrivate::s_renderers; +QHash SvgPrivate::s_renderers; QWeakPointer SvgPrivate::s_systemColorsCache; Svg::Svg(QObject *parent)