core: Add several QList::reserve() calls.
Reduces reallocations. Change-Id: Ib63539fb690a80245d8fe81ff8468e79ffa8e57c Reviewed-by: Marc Mutz <marc.mutz@kdab.com>bb10
parent
6b5029199d
commit
552fba2386
|
|
@ -790,6 +790,7 @@ QStringList QResourceRoot::children(int node) const
|
|||
offset += 4;
|
||||
const int child_off = (tree[offset+0] << 24) + (tree[offset+1] << 16) +
|
||||
(tree[offset+2] << 8) + (tree[offset+3] << 0);
|
||||
ret.reserve(child_count);
|
||||
for(int i = child_off; i < child_off+child_count; ++i)
|
||||
ret << name(i);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -357,6 +357,7 @@ void QSettingsPrivate::requestUpdate()
|
|||
QStringList QSettingsPrivate::variantListToStringList(const QVariantList &l)
|
||||
{
|
||||
QStringList result;
|
||||
result.reserve(l.count());
|
||||
QVariantList::const_iterator it = l.constBegin();
|
||||
for (; it != l.constEnd(); ++it)
|
||||
result.append(variantToString(*it));
|
||||
|
|
@ -374,7 +375,9 @@ QVariant QSettingsPrivate::stringListToVariantList(const QStringList &l)
|
|||
outStringList[i].remove(0, 1);
|
||||
} else {
|
||||
QVariantList variantList;
|
||||
for (int j = 0; j < l.count(); ++j)
|
||||
const int stringCount = l.count();
|
||||
variantList.reserve(stringCount);
|
||||
for (int j = 0; j < stringCount; ++j)
|
||||
variantList.append(stringToVariant(l.at(j)));
|
||||
return variantList;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -642,6 +642,7 @@ QList<QPair<QString, QString> > QUrlQuery::queryItems(QUrl::ComponentFormattingO
|
|||
QList<QPair<QString, QString> > result;
|
||||
Map::const_iterator it = d->itemList.constBegin();
|
||||
Map::const_iterator end = d->itemList.constEnd();
|
||||
result.reserve(d->itemList.count());
|
||||
for ( ; it != end; ++it)
|
||||
result << qMakePair(d->recodeToUser(it->first, encoding),
|
||||
d->recodeToUser(it->second, encoding));
|
||||
|
|
|
|||
|
|
@ -3222,6 +3222,7 @@ QModelIndexList QAbstractItemModel::persistentIndexList() const
|
|||
{
|
||||
Q_D(const QAbstractItemModel);
|
||||
QModelIndexList result;
|
||||
result.reserve(d->persistent.indexes.count());
|
||||
for (QHash<QModelIndex, QPersistentModelIndexData *>::const_iterator it = d->persistent.indexes.constBegin();
|
||||
it != d->persistent.indexes.constEnd(); ++it) {
|
||||
QPersistentModelIndexData *data = *it;
|
||||
|
|
|
|||
|
|
@ -379,6 +379,7 @@ QMimeData* QAbstractProxyModel::mimeData(const QModelIndexList &indexes) const
|
|||
{
|
||||
Q_D(const QAbstractProxyModel);
|
||||
QModelIndexList list;
|
||||
list.reserve(indexes.count());
|
||||
foreach(const QModelIndex &index, indexes)
|
||||
list << mapToSource(index);
|
||||
return d->model->mimeData(list);
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ QItemSelection QIdentityProxyModel::mapSelectionFromSource(const QItemSelection&
|
|||
|
||||
QItemSelection::const_iterator it = selection.constBegin();
|
||||
const QItemSelection::const_iterator end = selection.constEnd();
|
||||
proxySelection.reserve(selection.count());
|
||||
for ( ; it != end; ++it) {
|
||||
Q_ASSERT(it->model() == d->model);
|
||||
const QItemSelectionRange range(mapFromSource(it->topLeft()), mapFromSource(it->bottomRight()));
|
||||
|
|
@ -234,6 +235,7 @@ QItemSelection QIdentityProxyModel::mapSelectionToSource(const QItemSelection& s
|
|||
|
||||
QItemSelection::const_iterator it = selection.constBegin();
|
||||
const QItemSelection::const_iterator end = selection.constEnd();
|
||||
sourceSelection.reserve(selection.count());
|
||||
for ( ; it != end; ++it) {
|
||||
Q_ASSERT(it->model() == this);
|
||||
const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight()));
|
||||
|
|
@ -269,6 +271,7 @@ QModelIndexList QIdentityProxyModel::match(const QModelIndex& start, int role, c
|
|||
QModelIndexList::const_iterator it = sourceList.constBegin();
|
||||
const QModelIndexList::const_iterator end = sourceList.constEnd();
|
||||
QModelIndexList proxyList;
|
||||
proxyList.reserve(sourceList.count());
|
||||
for ( ; it != end; ++it)
|
||||
proxyList.append(mapFromSource(*it));
|
||||
return proxyList;
|
||||
|
|
|
|||
|
|
@ -1011,6 +1011,7 @@ QModelIndexPairList QSortFilterProxyModelPrivate::store_persistent_indexes()
|
|||
{
|
||||
Q_Q(QSortFilterProxyModel);
|
||||
QModelIndexPairList source_indexes;
|
||||
source_indexes.reserve(persistent.indexes.count());
|
||||
foreach (QPersistentModelIndexData *data, persistent.indexes) {
|
||||
QModelIndex proxy_index = data->index;
|
||||
QModelIndex source_index = q->mapToSource(proxy_index);
|
||||
|
|
@ -1030,7 +1031,10 @@ void QSortFilterProxyModelPrivate::update_persistent_indexes(
|
|||
{
|
||||
Q_Q(QSortFilterProxyModel);
|
||||
QModelIndexList from, to;
|
||||
for (int i = 0; i < source_indexes.count(); ++i) {
|
||||
const int numSourceIndexes = source_indexes.count();
|
||||
from.reserve(numSourceIndexes);
|
||||
to.reserve(numSourceIndexes);
|
||||
for (int i = 0; i < numSourceIndexes; ++i) {
|
||||
QModelIndex source_index = source_indexes.at(i).second;
|
||||
QModelIndex old_proxy_index = source_indexes.at(i).first;
|
||||
create_mapping(source_index.parent());
|
||||
|
|
@ -2013,7 +2017,9 @@ QMimeData *QSortFilterProxyModel::mimeData(const QModelIndexList &indexes) const
|
|||
{
|
||||
Q_D(const QSortFilterProxyModel);
|
||||
QModelIndexList source_indexes;
|
||||
for (int i = 0; i < indexes.count(); ++i)
|
||||
const int numIndexes = indexes.count();
|
||||
source_indexes.reserve(numIndexes);
|
||||
for (int i = 0; i < numIndexes; ++i)
|
||||
source_indexes << mapToSource(indexes.at(i));
|
||||
return d->model->mimeData(source_indexes);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,7 +257,9 @@ void QStringListModel::sort(int, Qt::SortOrder order)
|
|||
emit layoutAboutToBeChanged(QList<QPersistentModelIndex>(), VerticalSortHint);
|
||||
|
||||
QList<QPair<QString, int> > list;
|
||||
for (int i = 0; i < lst.count(); ++i)
|
||||
const int lstCount = lst.count();
|
||||
list.reserve(lstCount);
|
||||
for (int i = 0; i < lstCount; ++i)
|
||||
list.append(QPair<QString, int>(lst.at(i), i));
|
||||
|
||||
if (order == Qt::AscendingOrder)
|
||||
|
|
|
|||
|
|
@ -271,6 +271,7 @@ QVariantList QJsonArray::toVariantList() const
|
|||
QVariantList list;
|
||||
|
||||
if (a) {
|
||||
list.reserve(a->length);
|
||||
for (int i = 0; i < (int)a->length; ++i)
|
||||
list.append(QJsonValue(d, a, a->at(i)).toVariant());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ QStringList QJsonObject::keys() const
|
|||
return QStringList();
|
||||
|
||||
QStringList keys;
|
||||
|
||||
keys.reserve(o->length);
|
||||
for (uint i = 0; i < o->length; ++i) {
|
||||
QJsonPrivate::Entry *e = o->entryAt(i);
|
||||
keys.append(e->key());
|
||||
|
|
|
|||
|
|
@ -354,7 +354,9 @@ void QMimeData::setUrls(const QList<QUrl> &urls)
|
|||
{
|
||||
Q_D(QMimeData);
|
||||
QList<QVariant> list;
|
||||
for (int i = 0; i < urls.size(); ++i)
|
||||
const int numUrls = urls.size();
|
||||
list.reserve(numUrls);
|
||||
for (int i = 0; i < numUrls; ++i)
|
||||
list.append(urls.at(i));
|
||||
|
||||
d->setData(QLatin1String("text/uri-list"), list);
|
||||
|
|
|
|||
|
|
@ -434,6 +434,7 @@ QList<QMimeType> QMimeDatabase::mimeTypesForFileName(const QString &fileName) co
|
|||
QStringList matches = d->mimeTypeForFileName(fileName);
|
||||
QList<QMimeType> mimes;
|
||||
matches.sort(); // Make it deterministic
|
||||
mimes.reserve(matches.count());
|
||||
foreach (const QString &mime, matches)
|
||||
mimes.append(d->mimeTypeForName(mime));
|
||||
return mimes;
|
||||
|
|
|
|||
|
|
@ -541,6 +541,7 @@ QList<QMimeType> QMimeBinaryProvider::allMimeTypes()
|
|||
{
|
||||
QList<QMimeType> result;
|
||||
loadMimeTypeList();
|
||||
result.reserve(m_mimetypeNames.count());
|
||||
|
||||
for (QSet<QString>::const_iterator it = m_mimetypeNames.constBegin();
|
||||
it != m_mimetypeNames.constEnd(); ++it)
|
||||
|
|
|
|||
|
|
@ -435,7 +435,9 @@ QObjectList QPluginLoader::staticInstances()
|
|||
QObjectList instances;
|
||||
const StaticPluginList *plugins = staticPluginList();
|
||||
if (plugins) {
|
||||
for (int i = 0; i < plugins->size(); ++i)
|
||||
const int numPlugins = plugins->size();
|
||||
instances.reserve(numPlugins);
|
||||
for (int i = 0; i < numPlugins; ++i)
|
||||
instances += plugins->at(i).instance();
|
||||
}
|
||||
return instances;
|
||||
|
|
|
|||
|
|
@ -2454,6 +2454,7 @@ void QStateMachinePrivate::handleTransitionSignal(QObject *sender, int signalInd
|
|||
QMetaMethod method = meta->method(signalIndex);
|
||||
int argc = method.parameterCount();
|
||||
QList<QVariant> vargs;
|
||||
vargs.reserve(argc);
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
int type = method.parameterType(i);
|
||||
vargs.append(QVariant(type, argv[i+1]));
|
||||
|
|
|
|||
|
|
@ -2128,7 +2128,8 @@ QStringRef QRegularExpressionMatch::capturedRef(const QString &name) const
|
|||
QStringList QRegularExpressionMatch::capturedTexts() const
|
||||
{
|
||||
QStringList texts;
|
||||
for (int i = 0; i <= lastCapturedIndex(); ++i)
|
||||
texts.reserve(d->capturedCount);
|
||||
for (int i = 0; i < d->capturedCount; ++i)
|
||||
texts << captured(i);
|
||||
return texts;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -700,6 +700,7 @@ QByteArray QUtcTimeZonePrivate::systemTimeZoneId() const
|
|||
QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds() const
|
||||
{
|
||||
QList<QByteArray> result;
|
||||
result.reserve(utcDataTableSize);
|
||||
for (int i = 0; i < utcDataTableSize; ++i)
|
||||
result << utcId(utcData(i));
|
||||
std::sort(result.begin(), result.end()); // ### or already sorted??
|
||||
|
|
|
|||
Loading…
Reference in New Issue