summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Bastian <thierry.bastian@nokia.com>2009-03-26 09:41:53 (GMT)
committerThierry Bastian <thierry.bastian@nokia.com>2009-03-26 09:41:53 (GMT)
commit5ca5a64a5c714b18ef23c093307f9f4061235731 (patch)
treee1841e8b5ac83ea387614a17c7fbf016984394c6
parent262ce9e47036a60d5bd466e3f5cdc4006c7974e2 (diff)
downloadQt-5ca5a64a5c714b18ef23c093307f9f4061235731.zip
Qt-5ca5a64a5c714b18ef23c093307f9f4061235731.tar.gz
Qt-5ca5a64a5c714b18ef23c093307f9f4061235731.tar.bz2
Improved qVariantSetValue by reusing the internals if possible
This is possible if the type is the same of type < Char (simple types)
-rw-r--r--src/corelib/kernel/qvariant.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index d7b7e3c..284e68c 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -443,7 +443,18 @@ inline QVariant qVariantFromValue(const QVariant &t) { return t; }
template <typename T>
inline void qVariantSetValue(QVariant &v, const T &t)
{
- v = QVariant(qMetaTypeId<T>(reinterpret_cast<T *>(0)), &t);
+ //if possible we reuse the current QVariant private
+ const int type = qMetaTypeId<T>(reinterpret_cast<T *>(0));
+ QVariant::Private &d = v.data_ptr();
+ if (type <= int(QVariant::Char) || (type == d.type && v.isDetached())) {
+ d.type = type;
+ T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr);
+ if (QTypeInfo<T>::isComplex)
+ old->~T();
+ new (old) T(t); //call the copy constructor
+ } else {
+ v = QVariant(type, &t);
+ }
}
inline QVariant::QVariant() {}