summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-04-22 05:43:08 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-04-22 05:43:08 (GMT)
commitbef4438eea6fc44ef81c63772e10d2390586d16c (patch)
tree45fbafa226443463b202ca2aec71b7e22a992fa8
parentf2c5ea07b2ed5f96bd32f9a1d71ec9613c240fa6 (diff)
downloadQt-bef4438eea6fc44ef81c63772e10d2390586d16c.zip
Qt-bef4438eea6fc44ef81c63772e10d2390586d16c.tar.gz
Qt-bef4438eea6fc44ef81c63772e10d2390586d16c.tar.bz2
Fix merge error.
-rw-r--r--src/corelib/kernel/qvariant_p.h34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h
index 727a390..074575b 100644
--- a/src/corelib/kernel/qvariant_p.h
+++ b/src/corelib/kernel/qvariant_p.h
@@ -91,13 +91,36 @@ inline T *v_cast(QVariant::Private *d, T * = 0)
#endif
+
+//a simple template that avoids to allocate 2 memory chunks when creating a QVariant
+template <class T> class QVariantPrivateSharedEx : public QVariant::PrivateShared
+{
+public:
+ QVariantPrivateSharedEx() : QVariant::PrivateShared(&m_t) { }
+ QVariantPrivateSharedEx(const T&t) : QVariant::PrivateShared(&m_t), m_t(t) { }
+
+private:
+ T m_t;
+};
+
// constructs a new variant if copy is 0, otherwise copy-constructs
template <class T>
+inline void v_construct(QVariant::Private *x, const T &t)
+{
+ if (sizeof(T) > sizeof(QVariant::Private::Data)) {
+ x->data.shared = new QVariantPrivateSharedEx<T>(t);
+ x->is_shared = true;
+ } else {
+ new (&x->data.ptr) T(t);
+ }
+}
+
+template <class T>
inline void v_construct(QVariant::Private *x, const void *copy, T * = 0)
{
if (sizeof(T) > sizeof(QVariant::Private::Data)) {
- x->data.shared = copy ? new QVariant::PrivateShared(new T(*static_cast<const T *>(copy)))
- : new QVariant::PrivateShared(new T);
+ x->data.shared = copy ? new QVariantPrivateSharedEx<T>(*static_cast<const T *>(copy))
+ : new QVariantPrivateSharedEx<T>;
x->is_shared = true;
} else {
if (copy)
@@ -111,12 +134,15 @@ inline void v_construct(QVariant::Private *x, const void *copy, T * = 0)
template <class T>
inline void v_clear(QVariant::Private *d, T* = 0)
{
+
if (sizeof(T) > sizeof(QVariant::Private::Data)) {
- delete v_cast<T>(d);
- delete d->data.shared;
+ //now we need to cast
+ //because QVariant::PrivateShared doesn't have a virtual destructor
+ delete static_cast<QVariantPrivateSharedEx<T>*>(d->data.shared);
} else {
v_cast<T>(d)->~T();
}
+
}
QT_END_NAMESPACE