From d4cee10bf8e1460bc569e0ee392fd33d21f6cf80 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 14 Jun 2015 11:09:49 +0200 Subject: [PATCH] QMetaObjectBuilder: replace inefficient QLists with QVector The QMeta*Private classes are larger than a void*, and weren't marked as movable, so QList is horribly inefficient. Fix by holding them in QVector instead. Saves ~900B in text size on GCC 4.9 optimized C++11 AMD64 Linux builds, and tons of memory allocations. Change-Id: I313c965d7a0fea16f79e9fde04a972fc248e33aa Reviewed-by: Lars Knoll --- src/corelib/kernel/qmetaobjectbuilder.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index a1b8125121..62119c86d6 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -88,6 +88,7 @@ static inline Q_DECL_UNUSED const QMetaObjectPrivate *priv(const uint* data) class QMetaMethodBuilderPrivate { public: + QMetaMethodBuilderPrivate() {} // for QVector, don't use QMetaMethodBuilderPrivate (QMetaMethod::MethodType _methodType, const QByteArray& _signature, @@ -139,10 +140,12 @@ public: return signature.left(qMax(signature.indexOf('('), 0)); } }; +Q_DECLARE_TYPEINFO(QMetaMethodBuilderPrivate, Q_MOVABLE_TYPE); class QMetaPropertyBuilderPrivate { public: + QMetaPropertyBuilderPrivate() {} // for QVector, don't use QMetaPropertyBuilderPrivate (const QByteArray& _name, const QByteArray& _type, int notifierIdx=-1, int _revision = 0) @@ -176,10 +179,12 @@ public: flags &= ~f; } }; +Q_DECLARE_TYPEINFO(QMetaPropertyBuilderPrivate, Q_MOVABLE_TYPE); class QMetaEnumBuilderPrivate { public: + QMetaEnumBuilderPrivate() {} // for QVector, don't use QMetaEnumBuilderPrivate(const QByteArray& _name) : name(_name), isFlag(false) { @@ -190,6 +195,7 @@ public: QList keys; QList values; }; +Q_DECLARE_TYPEINFO(QMetaEnumBuilderPrivate, Q_MOVABLE_TYPE); class QMetaObjectBuilderPrivate { @@ -207,12 +213,12 @@ public: QByteArray className; const QMetaObject *superClass; QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction; - QList methods; - QList constructors; - QList properties; + QVector methods; + QVector constructors; + QVector properties; QList classInfoNames; QList classInfoValues; - QList enumerators; + QVector enumerators; QList relatedMetaObjects; int flags; }; @@ -1149,7 +1155,7 @@ void QMetaStringTable::writeBlob(char *out) const // Returns the sum of all parameters (including return type) for the given // \a methods. This is needed for calculating the size of the methods' // parameter type/name meta-data. -static int aggregateParameterCount(const QList &methods) +static int aggregateParameterCount(const QVector &methods) { int sum = 0; for (int i = 0; i < methods.size(); ++i) @@ -1330,7 +1336,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, Q_ASSERT(!buf || dataIndex == pmeta->methodData + d->methods.size() * 5 + (hasRevisionedMethods ? d->methods.size() : 0)); for (int x = 0; x < 2; ++x) { - QList &methods = (x == 0) ? d->methods : d->constructors; + QVector &methods = (x == 0) ? d->methods : d->constructors; for (index = 0; index < methods.size(); ++index) { QMetaMethodBuilderPrivate *method = &(methods[index]); QList paramTypeNames = method->parameterTypes();