Make use of the internal space for enum in QVariant

Enums are movable even if they have not been tagged as such, and
therefore can safely make use of the internal storage.

Change-Id: I3bec8556bfeb4a07cb30d918f8d1dd2565d6d94a
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
bb10
Olivier Goffart 2013-11-04 22:09:20 +01:00 committed by The Qt Project
parent 4fb04b0bd7
commit 9fda89f97d
2 changed files with 2 additions and 2 deletions

View File

@ -841,7 +841,7 @@ static void customConstruct(QVariant::Private *d, const void *copy)
// this logic should match with QVariantIntegrator::CanUseInternalSpace
if (size <= sizeof(QVariant::Private::Data)
&& (type.flags() & QMetaType::MovableType)) {
&& (type.flags() & (QMetaType::MovableType | QMetaType::IsEnumeration))) {
type.construct(&d->data.ptr, copy);
d->is_shared = false;
} else {

View File

@ -67,7 +67,7 @@ template<typename T>
struct QVariantIntegrator
{
static const bool CanUseInternalSpace = sizeof(T) <= sizeof(QVariant::Private::Data)
&& (!QTypeInfo<T>::isStatic);
&& ((!QTypeInfo<T>::isStatic) || Q_IS_ENUM(T));
};
Q_STATIC_ASSERT(QVariantIntegrator<double>::CanUseInternalSpace);
Q_STATIC_ASSERT(QVariantIntegrator<long int>::CanUseInternalSpace);