diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 2db4e07c99..c7d9c9767a 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -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(result); const QVariantList *list = v_cast(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(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(result); const QStringList *slist = v_cast(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") == 0) { *static_cast(result) =