From ba31fca51ce7bdbbc6acabda2f0ac05d2700507d Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 31 Mar 2009 11:09:41 +0200 Subject: make construction for known type faster There is one less test thanks to usage of reference instead of pointers --- src/corelib/kernel/qvariant.cpp | 46 ++++++++++++++++++++--------------------- src/corelib/kernel/qvariant_p.h | 11 ++++++++++ 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 96e5b4e..ea66658 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1608,44 +1608,44 @@ QVariant::QVariant(double val) { d.is_null = false; d.type = Double; d.data.d = val; } QVariant::QVariant(const QByteArray &val) -{ d.is_null = false; d.type = ByteArray; v_construct(&d, &val); } +{ d.is_null = false; d.type = ByteArray; v_construct(&d, val); } QVariant::QVariant(const QBitArray &val) -{ d.is_null = false; d.type = BitArray; v_construct(&d, &val); } +{ d.is_null = false; d.type = BitArray; v_construct(&d, val); } QVariant::QVariant(const QString &val) -{ d.is_null = false; d.type = String; v_construct(&d, &val); } +{ d.is_null = false; d.type = String; v_construct(&d, val); } QVariant::QVariant(const QChar &val) -{ d.is_null = false; d.type = Char; v_construct(&d, &val); } +{ d.is_null = false; d.type = Char; v_construct(&d, val); } QVariant::QVariant(const QLatin1String &val) -{ QString str(val); d.is_null = false; d.type = String; v_construct(&d, &str); } +{ QString str(val); d.is_null = false; d.type = String; v_construct(&d, str); } QVariant::QVariant(const QStringList &val) -{ d.is_null = false; d.type = StringList; v_construct(&d, &val); } +{ d.is_null = false; d.type = StringList; v_construct(&d, val); } QVariant::QVariant(const QDate &val) -{ d.is_null = false; d.type = Date; v_construct(&d, &val); } +{ d.is_null = false; d.type = Date; v_construct(&d, val); } QVariant::QVariant(const QTime &val) -{ d.is_null = false; d.type = Time; v_construct(&d, &val); } +{ d.is_null = false; d.type = Time; v_construct(&d, val); } QVariant::QVariant(const QDateTime &val) -{ d.is_null = false; d.type = DateTime; v_construct(&d, &val); } +{ d.is_null = false; d.type = DateTime; v_construct(&d, val); } QVariant::QVariant(const QList &list) -{ d.is_null = false; d.type = List; v_construct(&d, &list); } +{ d.is_null = false; d.type = List; v_construct(&d, list); } QVariant::QVariant(const QMap &map) -{ d.is_null = false; d.type = Map; v_construct(&d, &map); } +{ d.is_null = false; d.type = Map; v_construct(&d, map); } QVariant::QVariant(const QHash &hash) -{ d.is_null = false; d.type = Hash; v_construct(&d, &hash); } +{ d.is_null = false; d.type = Hash; v_construct(&d, hash); } #ifndef QT_NO_GEOM_VARIANT -QVariant::QVariant(const QPoint &pt) { d.is_null = false; d.type = Point; v_construct(&d, &pt); } -QVariant::QVariant(const QPointF &pt) { d.is_null = false; d.type = PointF; v_construct(&d, &pt); } -QVariant::QVariant(const QRectF &r) { d.is_null = false; d.type = RectF; v_construct(&d, &r); } -QVariant::QVariant(const QLineF &l) { d.is_null = false; d.type = LineF; v_construct(&d, &l); } -QVariant::QVariant(const QLine &l) { d.is_null = false; d.type = Line; v_construct(&d, &l); } -QVariant::QVariant(const QRect &r) { d.is_null = false; d.type = Rect; v_construct(&d, &r); } -QVariant::QVariant(const QSize &s) { d.is_null = false; d.type = Size; v_construct(&d, &s); } -QVariant::QVariant(const QSizeF &s) { d.is_null = false; d.type = SizeF; v_construct(&d, &s); } +QVariant::QVariant(const QPoint &pt) { d.is_null = false; d.type = Point; v_construct(&d, pt); } +QVariant::QVariant(const QPointF &pt) { d.is_null = false; d.type = PointF; v_construct(&d, pt); } +QVariant::QVariant(const QRectF &r) { d.is_null = false; d.type = RectF; v_construct(&d, r); } +QVariant::QVariant(const QLineF &l) { d.is_null = false; d.type = LineF; v_construct(&d, l); } +QVariant::QVariant(const QLine &l) { d.is_null = false; d.type = Line; v_construct(&d, l); } +QVariant::QVariant(const QRect &r) { d.is_null = false; d.type = Rect; v_construct(&d, r); } +QVariant::QVariant(const QSize &s) { d.is_null = false; d.type = Size; v_construct(&d, s); } +QVariant::QVariant(const QSizeF &s) { d.is_null = false; d.type = SizeF; v_construct(&d, s); } #endif -QVariant::QVariant(const QUrl &u) { d.is_null = false; d.type = Url; v_construct(&d, &u); } -QVariant::QVariant(const QLocale &l) { d.is_null = false; d.type = Locale; v_construct(&d, &l); } +QVariant::QVariant(const QUrl &u) { d.is_null = false; d.type = Url; v_construct(&d, u); } +QVariant::QVariant(const QLocale &l) { d.is_null = false; d.type = Locale; v_construct(&d, l); } #ifndef QT_NO_REGEXP -QVariant::QVariant(const QRegExp ®Exp) { d.is_null = false; d.type = RegExp; v_construct(&d, ®Exp); } +QVariant::QVariant(const QRegExp ®Exp) { d.is_null = false; d.type = RegExp; v_construct(&d, regExp); } #endif QVariant::QVariant(Qt::GlobalColor color) { create(62, &color); } diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index a5ba9ff..033b760 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -105,6 +105,17 @@ private: // constructs a new variant if copy is 0, otherwise copy-constructs template +inline void v_construct(QVariant::Private *x, const T &t) +{ + if (sizeof(T) > sizeof(QVariant::Private::Data)) { + x->data.shared = new QVariantPrivateSharedEx(t); + x->is_shared = true; + } else { + new (&x->data.ptr) T(t); + } +} + +template inline void v_construct(QVariant::Private *x, const void *copy, T * = 0) { if (sizeof(T) > sizeof(QVariant::Private::Data)) { -- cgit v0.12