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) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2016-01-05 14:08:25 +01:00
parent 771220ebc8
commit 68e915c623
2 changed files with 12 additions and 61 deletions

View File

@ -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

View File

@ -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<QFontEngine> m_fontEngine; // 4 bytes per item
QExplicitlySharedDataPointer<QStaticTextUserData> m_userData; // 8 bytes per item
// ================
// 43 bytes per item
};
class QStaticText;