Use static-less QMetaType API in QVariant.
This patch improves performance when constructing a custom type in a QVariant by ~ 7-20% (instructions count) depending on the type size and metatype attributes. Change-Id: Ic2707ff5abd689b66e23c1794f111504bf9b3b01 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
214e031d56
commit
1b23336a29
@ -787,7 +787,8 @@ const QVariant::Handler qt_dummy_variant_handler = {
|
||||
|
||||
static void customConstruct(QVariant::Private *d, const void *copy)
|
||||
{
|
||||
const uint size = QMetaType::sizeOf(d->type);
|
||||
const QMetaType type(d->type);
|
||||
const uint size = type.sizeOf();
|
||||
if (!size) {
|
||||
d->type = QVariant::Invalid;
|
||||
return;
|
||||
@ -795,11 +796,11 @@ static void customConstruct(QVariant::Private *d, const void *copy)
|
||||
|
||||
// this logic should match with QVariantIntegrator::CanUseInternalSpace
|
||||
if (size <= sizeof(QVariant::Private::Data)
|
||||
&& (QMetaType::typeFlags(d->type) & QMetaType::MovableType)) {
|
||||
QMetaType::construct(d->type, &d->data.ptr, copy);
|
||||
&& (type.flags() & QMetaType::MovableType)) {
|
||||
type.construct(&d->data.ptr, copy);
|
||||
d->is_shared = false;
|
||||
} else {
|
||||
void *ptr = QMetaType::create(d->type, copy);
|
||||
void *ptr = type.create(copy);
|
||||
d->is_shared = true;
|
||||
d->data.shared = new QVariant::PrivateShared(ptr);
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ struct BigClass
|
||||
double n,i,e,r,o,b;
|
||||
};
|
||||
Q_STATIC_ASSERT(sizeof(BigClass) > sizeof(QVariant::Private::Data));
|
||||
Q_DECLARE_TYPEINFO(BigClass, Q_MOVABLE_TYPE);
|
||||
Q_DECLARE_METATYPE(BigClass);
|
||||
|
||||
struct SmallClass
|
||||
@ -97,6 +98,7 @@ struct SmallClass
|
||||
char s;
|
||||
};
|
||||
Q_STATIC_ASSERT(sizeof(SmallClass) <= sizeof(QVariant::Private::Data));
|
||||
Q_DECLARE_TYPEINFO(SmallClass, Q_MOVABLE_TYPE);
|
||||
Q_DECLARE_METATYPE(SmallClass);
|
||||
|
||||
void tst_qvariant::testBound()
|
||||
|
Loading…
Reference in New Issue
Block a user