QMetaObjectBuilder: replace inefficient QLists with QVector

The QMeta*Private classes are larger than a void*, and weren't
marked as movable, so QList<QMeta*Private> 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 <lars.knoll@theqtcompany.com>
bb10
Marc Mutz 2015-06-14 11:09:49 +02:00
parent 2d9700c041
commit d4cee10bf8
1 changed files with 12 additions and 6 deletions

View File

@ -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<QByteArray> keys;
QList<int> values;
};
Q_DECLARE_TYPEINFO(QMetaEnumBuilderPrivate, Q_MOVABLE_TYPE);
class QMetaObjectBuilderPrivate
{
@ -207,12 +213,12 @@ public:
QByteArray className;
const QMetaObject *superClass;
QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction;
QList<QMetaMethodBuilderPrivate> methods;
QList<QMetaMethodBuilderPrivate> constructors;
QList<QMetaPropertyBuilderPrivate> properties;
QVector<QMetaMethodBuilderPrivate> methods;
QVector<QMetaMethodBuilderPrivate> constructors;
QVector<QMetaPropertyBuilderPrivate> properties;
QList<QByteArray> classInfoNames;
QList<QByteArray> classInfoValues;
QList<QMetaEnumBuilderPrivate> enumerators;
QVector<QMetaEnumBuilderPrivate> enumerators;
QList<const QMetaObject *> 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<QMetaMethodBuilderPrivate> &methods)
static int aggregateParameterCount(const QVector<QMetaMethodBuilderPrivate> &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<QMetaMethodBuilderPrivate> &methods = (x == 0) ? d->methods : d->constructors;
QVector<QMetaMethodBuilderPrivate> &methods = (x == 0) ? d->methods : d->constructors;
for (index = 0; index < methods.size(); ++index) {
QMetaMethodBuilderPrivate *method = &(methods[index]);
QList<QByteArray> paramTypeNames = method->parameterTypes();