summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qfontengine.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-02-18 12:00:27 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-03-04 10:37:25 +0000
commit7d2c7ca8fad2d8177599ba3a4851c48d3baf5772 (patch)
treef29457ec891fb028cc113e7d0eef35bfdb17eb2f /src/gui/text/qfontengine.cpp
parent5cd455dca309d0d031057ab40ff607d144683d43 (diff)
QFontEngine: use RAII for font_, face_ members
Wrap the pairs of (void *ptr, void (*dtor)(void*)) in essentially a std::unique_ptr. This simplifies code and provides the correct implicit destruction, so we can drop the explicit glyph-cache clear()ing in ~QFontEngine(), leaving that job to ~QLinkedList. A subsequent change will turn the QLinkedList into a C array, the clearing of which would otherwise cause excessive code bloat. Since we can't use std::unique_ptr, yet, provide a hand-rolled replacement for now, marking it for replacement with unique_ptr once we can use it. Make that a local type instead of providing a Qt-wide unique_ptr so we don't accidentally lock ourselves into a half-baked std clone we can't get rid of anymore. To prepare unique_ptr use with the same type-erased deleter (function pointer) as now, replace a nullptr destroy_function with a no-op function, so ~unique_ptr doesn't crash when we port to it later. Because QFreetypeFace contains the same construct and shares payloads with QFontEngine, use the Holder there, too. Even saves 150b in text size on optimized GCC 5.3 AMD64 builds. Change-Id: I5ca11a3e6e1ff9e06199124403d96e1b280f3eb2 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/gui/text/qfontengine.cpp')
-rw-r--r--src/gui/text/qfontengine.cpp25
1 files changed, 6 insertions, 19 deletions
diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index 7c0492bb1a..96f7e06a47 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -246,8 +246,8 @@ Q_AUTOTEST_EXPORT QList<QFontEngine *> QFontEngine_stopCollectingEngines()
QFontEngine::QFontEngine(Type type)
: m_type(type), ref(0),
- font_(0), font_destroy_func(0),
- face_(0), face_destroy_func(0),
+ font_(),
+ face_(),
m_minLeftBearing(kBearingNotInitialized),
m_minRightBearing(kBearingNotInitialized)
{
@@ -269,17 +269,6 @@ QFontEngine::QFontEngine(Type type)
QFontEngine::~QFontEngine()
{
- m_glyphCaches.clear();
-
- if (font_ && font_destroy_func) {
- font_destroy_func(font_);
- font_ = 0;
- }
- if (face_ && face_destroy_func) {
- face_destroy_func(face_);
- face_ = 0;
- }
-
#ifdef QT_BUILD_INTERNAL
if (enginesCollector)
enginesCollector->removeOne(this);
@@ -334,10 +323,9 @@ void *QFontEngine::harfbuzzFont() const
hbFont->x_scale = (((qint64)hbFont->x_ppem << 6) * 0x10000L + (emSquare >> 1)) / emSquare;
hbFont->y_scale = (((qint64)hbFont->y_ppem << 6) * 0x10000L + (emSquare >> 1)) / emSquare;
- font_ = (void *)hbFont;
- font_destroy_func = free;
+ font_ = Holder(hbFont, free);
}
- return font_;
+ return font_.get();
}
void *QFontEngine::harfbuzzFace() const
@@ -357,10 +345,9 @@ void *QFontEngine::harfbuzzFace() const
Q_CHECK_PTR(hbFace);
hbFace->isSymbolFont = symbol;
- face_ = (void *)hbFace;
- face_destroy_func = hb_freeFace;
+ face_ = Holder(hbFace, hb_freeFace);
}
- return face_;
+ return face_.get();
}
bool QFontEngine::supportsScript(QChar::Script script) const