From 9f09fed72f87c9379fcbfd51cd6463b5c470814f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 3 Jan 2016 11:24:07 -0200 Subject: QVariant: use v_construct instead of duplicating logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v_construct does what we want, so use it. This is required for the next commit, which solves a GCC 6 warning issue. Change-Id: Ibc83b9f7e3bc4962ae35ffff1425ed5f035f631a Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Jędrzej Nowacki --- src/corelib/kernel/qvariant_p.h | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index 4a090b5f12..4a7df1ad8d 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -116,13 +117,13 @@ inline void v_construct(QVariant::Private *x, const void *copy, T * = 0) if (!QVariantIntegrator::CanUseInternalSpace) { x->data.shared = copy ? new QVariantPrivateSharedEx(*static_cast(copy)) : new QVariantPrivateSharedEx; - x->is_shared = true; } else { if (copy) new (&x->data.ptr) T(*static_cast(copy)); else new (&x->data.ptr) T(); } + x->is_shared = !QVariantIntegrator::CanUseInternalSpace; } template @@ -130,10 +131,10 @@ inline void v_construct(QVariant::Private *x, const T &t) { if (!QVariantIntegrator::CanUseInternalSpace) { x->data.shared = new QVariantPrivateSharedEx(t); - x->is_shared = true; } else { new (&x->data.ptr) T(t); } + x->is_shared = !QVariantIntegrator::CanUseInternalSpace; } // deletes the internal structures @@ -327,39 +328,11 @@ protected: template class QVariantConstructor { - template::CanUseInternalSpace> - struct CallConstructor {}; - - template - struct CallConstructor - { - CallConstructor(const QVariantConstructor &tc) - { - if (tc.m_copy) - new (&tc.m_x->data.ptr) T(*static_cast(tc.m_copy)); - else - new (&tc.m_x->data.ptr) T(); - tc.m_x->is_shared = false; - } - }; - - template - struct CallConstructor - { - CallConstructor(const QVariantConstructor &tc) - { - Q_STATIC_ASSERT(QTypeInfo::isComplex || sizeof(T) > sizeof(QVariant::Private::Data)); - tc.m_x->data.shared = tc.m_copy ? new QVariantPrivateSharedEx(*static_cast(tc.m_copy)) - : new QVariantPrivateSharedEx; - tc.m_x->is_shared = true; - } - }; - template::IsAccepted> struct FilteredConstructor { FilteredConstructor(const QVariantConstructor &tc) { - CallConstructor tmp(tc); + v_construct(tc.m_x, tc.m_copy); tc.m_x->is_null = !tc.m_copy; } }; -- cgit v1.2.3