summaryrefslogtreecommitdiff
path: root/src/gui/text/qharfbuzzng.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/qharfbuzzng.cpp
parent5cd455dca309d0d031057ab40ff607d144683d43 (diff)
downloadqtbase-7d2c7ca8fad2d8177599ba3a4851c48d3baf5772.tar.gz
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/qharfbuzzng.cpp')
-rw-r--r--src/gui/text/qharfbuzzng.cpp20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/gui/text/qharfbuzzng.cpp b/src/gui/text/qharfbuzzng.cpp
index e33b461401..55ef9f0d15 100644
--- a/src/gui/text/qharfbuzzng.cpp
+++ b/src/gui/text/qharfbuzzng.cpp
@@ -678,14 +678,10 @@ hb_face_t *hb_qt_face_get_for_engine(QFontEngine *fe)
{
Q_ASSERT(fe && fe->type() != QFontEngine::Multi);
- if (Q_UNLIKELY(!fe->face_)) {
- fe->face_ = _hb_qt_face_create(fe);
- if (Q_UNLIKELY(!fe->face_))
- return NULL;
- fe->face_destroy_func = _hb_qt_face_release;
- }
+ if (Q_UNLIKELY(!fe->face_))
+ fe->face_ = QFontEngine::Holder(_hb_qt_face_create(fe), _hb_qt_face_release);
- return static_cast<hb_face_t *>(fe->face_);
+ return static_cast<hb_face_t *>(fe->face_.get());
}
@@ -728,14 +724,10 @@ hb_font_t *hb_qt_font_get_for_engine(QFontEngine *fe)
{
Q_ASSERT(fe && fe->type() != QFontEngine::Multi);
- if (Q_UNLIKELY(!fe->font_)) {
- fe->font_ = _hb_qt_font_create(fe);
- if (Q_UNLIKELY(!fe->font_))
- return NULL;
- fe->font_destroy_func = _hb_qt_font_release;
- }
+ if (Q_UNLIKELY(!fe->font_))
+ fe->font_ = QFontEngine::Holder(_hb_qt_font_create(fe), _hb_qt_font_release);
- return static_cast<hb_font_t *>(fe->font_);
+ return static_cast<hb_font_t *>(fe->font_.get());
}
QT_END_NAMESPACE