From ff6156204d2cc33771540ef71500605817dc4911 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 9 Jul 2021 15:51:40 +0200 Subject: 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 Reviewed-by: Friedemann Kleint --- tests/auto/gui/painting/qcolor/tst_qcolor.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/auto/gui/painting') diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp index 03cece5135..5c93a41b71 100644 --- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp +++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp @@ -1861,7 +1861,7 @@ void tst_QColor::qcolorprofile() { QFETCH(float, gammaC); QFETCH(int, tolerance); - QColorTrcLut *cp = QColorTrcLut::fromGamma(gammaC); + std::shared_ptr cp = QColorTrcLut::fromGamma(gammaC); // Test we are accurate for most values after converting through gamma-correction. int error = 0; @@ -1872,7 +1872,6 @@ void tst_QColor::qcolorprofile() error += qAbs(qRed(cin) - qRed(cout)); } QVERIFY(error <= tolerance); - delete cp; } QTEST_MAIN(tst_QColor) -- cgit v1.2.3