From 68e915c623613d32526be1a7c0d9b6b0d8322209 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 5 Jan 2016 14:08:25 +0100 Subject: [PATCH] QStaticTextItem: use smart pointer members ... so we can drop the user-defined copy special member functions and the destructor. As a side-effect, enables the move special member functions, which were previously inhibited by the presence of the now-removed functions, and makes the copy constructor safe for self-assignment. Change-Id: I430f83a6a08b1f5ee94b52f52e4d80fa1139d1c1 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/gui/text/qstatictext.cpp | 21 --------------- src/gui/text/qstatictext_p.h | 52 +++++++++--------------------------- 2 files changed, 12 insertions(+), 61 deletions(-) diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp index 74f4b10305..62c24797dc 100644 --- a/src/gui/text/qstatictext.cpp +++ b/src/gui/text/qstatictext.cpp @@ -700,25 +700,4 @@ void QStaticTextPrivate::init() needsRelayout = false; } -QStaticTextItem::~QStaticTextItem() -{ - if (m_userData != 0 && !m_userData->ref.deref()) - delete m_userData; - setFontEngine(0); -} - -void QStaticTextItem::setFontEngine(QFontEngine *fe) -{ - if (m_fontEngine == fe) - return; - - if (m_fontEngine != 0 && !m_fontEngine->ref.deref()) - delete m_fontEngine; - - m_fontEngine = fe; - - if (m_fontEngine != 0) - m_fontEngine->ref.ref(); -} - QT_END_NAMESPACE diff --git a/src/gui/text/qstatictext_p.h b/src/gui/text/qstatictext_p.h index 49ca24d51c..e654b8329d 100644 --- a/src/gui/text/qstatictext_p.h +++ b/src/gui/text/qstatictext_p.h @@ -75,46 +75,18 @@ public: userDataNeedsUpdate(0), usesRawFont(0), m_fontEngine(0), m_userData(0) {} - QStaticTextItem(const QStaticTextItem &other) - { - operator=(other); - } - - void operator=(const QStaticTextItem &other) - { - glyphPositions = other.glyphPositions; - glyphs = other.glyphs; - numGlyphs = other.numGlyphs; - font = other.font; - color = other.color; - useBackendOptimizations = other.useBackendOptimizations; - userDataNeedsUpdate = other.userDataNeedsUpdate; - usesRawFont = other.usesRawFont; - - m_fontEngine = 0; - m_userData = 0; - setUserData(other.userData()); - setFontEngine(other.fontEngine()); - } - - ~QStaticTextItem(); - void setUserData(QStaticTextUserData *newUserData) { - if (m_userData == newUserData) - return; - - if (m_userData != 0 && !m_userData->ref.deref()) - delete m_userData; - m_userData = newUserData; - if (m_userData != 0) - m_userData->ref.ref(); } - QStaticTextUserData *userData() const { return m_userData; } + QStaticTextUserData *userData() const { return m_userData.data(); } - void setFontEngine(QFontEngine *fe); - QFontEngine *fontEngine() const { return m_fontEngine; } + void setFontEngine(QFontEngine *fe) + { + m_fontEngine = fe; + } + + QFontEngine *fontEngine() const { return m_fontEngine.data(); } union { QFixedPoint *glyphPositions; // 8 bytes per glyph @@ -135,11 +107,11 @@ public: char userDataNeedsUpdate : 1; // char usesRawFont : 1; // -private: // Needs special handling in setters, so private to avoid abuse - QFontEngine *m_fontEngine; // 4 bytes per item - QStaticTextUserData *m_userData; // 8 bytes per item - // ================ - // 43 bytes per item +private: // private to avoid abuse + QExplicitlySharedDataPointer m_fontEngine; // 4 bytes per item + QExplicitlySharedDataPointer m_userData; // 8 bytes per item + // ================ + // 43 bytes per item }; class QStaticText;