summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qvariant.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-07-22 15:17:16 -0700
committerThiago Macieira <thiago.macieira@intel.com>2022-07-27 12:35:50 -0700
commitb665ffbce2bf6af92d1189cfadc36d356e21fcfa (patch)
tree8f5e0fd1b19567862723eb3c245c90188f651cb0 /src/corelib/kernel/qvariant.cpp
parent011570285a22661e5d353cb8527392de01981a78 (diff)
QVariant: optimize copying for trivially copyable payloads
If the payload is trivially copyable and is using the internal space, then it's already been copied by the copying of QVariant::Private. No further work is needed. Change-Id: I3859764fed084846bcb0fffd170446a4e474efb7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qvariant.cpp')
-rw-r--r--src/corelib/kernel/qvariant.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 9d89178428..5f0e759cf5 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -281,6 +281,20 @@ static void customClear(QVariant::Private *d)
}
}
+static QVariant::Private clonePrivate(const QVariant::Private &other)
+{
+ QVariant::Private d = other;
+ if (d.is_shared) {
+ d.data.shared->ref.ref();
+ } else if (const QtPrivate::QMetaTypeInterface *iface = d.typeInterface()) {
+ Q_ASSERT(d.canUseInternalSpace(iface));
+
+ // if not trivially copyable, ask to copy
+ if (iface->copyCtr)
+ QtMetaTypePrivate::copyConstruct(iface, d.data.data, other.data.data);
+ }
+ return d;
+}
} // anonymous used to hide QVariant handlers
@@ -512,15 +526,8 @@ QVariant::~QVariant()
*/
QVariant::QVariant(const QVariant &p)
- : d(p.d)
+ : d(clonePrivate(p.d))
{
- if (d.is_shared) {
- d.data.shared->ref.ref();
- } else if (const QtPrivate::QMetaTypeInterface *iface = d.typeInterface()) {
- // ask QMetaType to copy for us
- Q_ASSERT(d.canUseInternalSpace(iface));
- d.type().construct(d.data.data, p.constData());
- }
}
/*!
@@ -1004,14 +1011,7 @@ QVariant &QVariant::operator=(const QVariant &variant)
return *this;
clear();
- if (variant.d.is_shared) {
- variant.d.data.shared->ref.ref();
- d = variant.d;
- } else {
- d = variant.d;
- d.type().construct(d.data.data, variant.constData());
- }
-
+ d = clonePrivate(variant.d);
return *this;
}