QVariant: use reserve in convert()

... to optimize memory allocation.

Change-Id: I7f644955be779c3651683401a7985a265b69ca6f
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Anton Kudryavtsev 2016-01-21 22:07:25 +03:00
parent 720d1792f2
commit 0f51686a69

View File

@ -560,7 +560,9 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
if (d->type == QVariant::List) {
QStringList *slst = static_cast<QStringList *>(result);
const QVariantList *list = v_cast<QVariantList >(d);
for (int i = 0; i < list->size(); ++i)
const int size = list->size();
slst->reserve(size);
for (int i = 0; i < size; ++i)
slst->append(list->at(i).toString());
} else if (d->type == QVariant::String) {
QStringList *slst = static_cast<QStringList *>(result);
@ -826,7 +828,9 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
if (d->type == QVariant::StringList) {
QVariantList *lst = static_cast<QVariantList *>(result);
const QStringList *slist = v_cast<QStringList>(d);
for (int i = 0; i < slist->size(); ++i)
const int size = slist->size();
lst->reserve(size);
for (int i = 0; i < size; ++i)
lst->append(QVariant(slist->at(i)));
} else if (qstrcmp(QMetaType::typeName(d->type), "QList<QVariant>") == 0) {
*static_cast<QVariantList *>(result) =