diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2021-07-09 15:51:40 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2021-07-12 22:16:41 +0200 |
commit | ff6156204d2cc33771540ef71500605817dc4911 (patch) | |
tree | 7e9a6bf2a5e254facf863a256666e02a6e5869f3 /src/gui/kernel/qguiapplication.cpp | |
parent | d1d9caf12d103957dccc867c349c4514a28cfe6c (diff) |
QColorTrcLut: hold in shared_ptr
... instead of raw pointers or QSharedPointer.
Raw pointers are, of course, a no-no in modern code. In particular,
when the result is then held in shared_ptr or QSharedPointer,
make_shared or QSharedPointer::create() should be used to reduce
number of memory allocations.
Since this is private API, we're free to use std::shared_ptr, which
does only half the atomic operations on copies, compared to
QSharedPointer, so is more efficient.
For either make_shared or QSharedPointer::create(), we need to work
around the private ctor, which we do by inheriting a member-function
local class from QColorTrcLut and make_shared'ing that. As a
member-function-local class, it has access to the otherwise private
parts of QColorTrcLut, including its default constructor. As a public
subclass, shared_ptr has no problem performing the derived-to-base
pointer adjustment in the return statement. This way, we can use
make_shared even though our target's class' ctor is private.
Change-Id: Icb11249b54cd5e544e692f6a0bf1f9dda1710454
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/gui/kernel/qguiapplication.cpp')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 101b33f94a..e6bc471ec7 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -4156,10 +4156,8 @@ void QGuiApplicationPrivate::notifyDragStarted(const QDrag *drag) const QColorTrcLut *QGuiApplicationPrivate::colorProfileForA8Text() { #ifdef Q_OS_WIN - if (!m_a8ColorProfile){ - QColorTrcLut *cs = QColorTrcLut::fromGamma(2.31); // This is a hard-coded thing for Windows text rendering - m_a8ColorProfile.reset(cs); - } + if (!m_a8ColorProfile) + m_a8ColorProfile = QColorTrcLut::fromGamma(2.31); // This is a hard-coded thing for Windows text rendering return m_a8ColorProfile.get(); #else return colorProfileForA32Text(); @@ -4168,10 +4166,8 @@ const QColorTrcLut *QGuiApplicationPrivate::colorProfileForA8Text() const QColorTrcLut *QGuiApplicationPrivate::colorProfileForA32Text() { - if (!m_a32ColorProfile) { - QColorTrcLut *cs = QColorTrcLut::fromGamma(fontSmoothingGamma); - m_a32ColorProfile.reset(cs); - } + if (!m_a32ColorProfile) + m_a32ColorProfile = QColorTrcLut::fromGamma(fontSmoothingGamma); return m_a32ColorProfile.get(); } |