aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergio Martins <[email protected]>2015-08-29 10:02:22 +0100
committerSergio Martins <[email protected]>2015-08-29 10:02:22 +0100
commit201db6ae30c0e067afc6189eb85035e1d178d6cf (patch)
treebf03602441084ca7714d5b60063d3a1f95ff11e3
parent601021b3b29800edd934ec43360720d5ba3f7402 (diff)
More reserve() calls
-rw-r--r--src/server/handler/fetchhelper.cpp7
-rw-r--r--src/server/handler/list.cpp3
-rw-r--r--src/server/handler/searchpersistent.cpp1
-rw-r--r--src/server/handlerhelper.cpp1
-rw-r--r--src/server/resourcemanager.cpp4
-rw-r--r--src/server/storage/dbinitializer_p.cpp1
-rw-r--r--src/server/storage/dbintrospector.cpp4
-rw-r--r--src/server/storage/notificationcollector.cpp2
-rw-r--r--src/server/storage/storagedebugger.cpp8
-rw-r--r--src/server/storagejanitor.cpp1
10 files changed, 26 insertions, 6 deletions
diff --git a/src/server/handler/fetchhelper.cpp b/src/server/handler/fetchhelper.cpp
index 8d16d11..2ea7b06 100644
--- a/src/server/handler/fetchhelper.cpp
+++ b/src/server/handler/fetchhelper.cpp
@@ -484,12 +484,13 @@ bool FetchHelper::fetchItems()
tagIds << tagQuery.value(TagQueryTagIdColumn).toLongLong();
tagQuery.next();
}
+
+ tags.reserve(tagIds.count());
if (!fullTagsRequested) {
Q_FOREACH (qint64 tagId, tagIds) {
tags << Protocol::FetchTagsResponse(tagId);
}
} else {
- tags.reserve(tagIds.count());
Q_FOREACH (qint64 tagId, tagIds) {
tags << HandlerHelper::fetchTagsResponse(Tag::retrieveById(tagId));
}
@@ -526,7 +527,9 @@ bool FetchHelper::fetchItems()
throw HandlerException("Unable to list item relations");
}
QVector<Protocol::FetchRelationsResponse> relations;
- Q_FOREACH (const Relation &rel, qb.result()) {
+ const auto result = qb.result();
+ relations.reserve(result.size());
+ Q_FOREACH (const Relation &rel, result) {
relations << HandlerHelper::fetchRelationsResponse(rel);
}
response.setRelations(relations);
diff --git a/src/server/handler/list.cpp b/src/server/handler/list.cpp
index f5a4ac2..6f78c56 100644
--- a/src/server/handler/list.cpp
+++ b/src/server/handler/list.cpp
@@ -104,6 +104,7 @@ void List::listCollection(const Collection &root, const QStack<Collection> &ance
QStack<CollectionAttribute::List> ancestorAttributes;
//backwards compatibilty, collectionToByteArray will automatically fall-back to id + remoteid
if (!mAncestorAttributes.isEmpty()) {
+ ancestorAttributes.reserve(ancestors.size());
Q_FOREACH (const Collection &col, ancestors) {
ancestorAttributes.push(getAttributes(col, mAncestorAttributes));
}
@@ -171,6 +172,7 @@ static QSqlQuery getAttributeQuery(const QVariantList &ids, const QSet<QByteArra
if (!requestedAttributes.isEmpty()) {
QVariantList attributes;
+ attributes.reserve(requestedAttributes.size());
Q_FOREACH (const QByteArray &type, requestedAttributes) {
attributes << type;
}
@@ -280,6 +282,7 @@ void List::retrieveCollections(const Collection &topParent, int depth)
if (!mMimeTypes.isEmpty()) {
qb.addJoin(QueryBuilder::LeftJoin, CollectionMimeTypeRelation::tableName(), CollectionMimeTypeRelation::leftColumn(), Collection::idFullColumnName());
QVariantList mimeTypeFilter;
+ mimeTypeFilter.reserve(mMimeTypes.size());
Q_FOREACH(MimeType::Id mtId, mMimeTypes) {
mimeTypeFilter << mtId;
}
diff --git a/src/server/handler/searchpersistent.cpp b/src/server/handler/searchpersistent.cpp
index 5dec5c9..f07fb89 100644
--- a/src/server/handler/searchpersistent.cpp
+++ b/src/server/handler/searchpersistent.cpp
@@ -59,6 +59,7 @@ bool SearchPersistent::parseStream()
QStringList queryCollections;
QVector<qint64> queryColIds = cmd.queryCollections();
qSort(queryColIds);
+ queryCollections.reserve(queryColIds.size());
Q_FOREACH (qint64 col, queryColIds) {
queryCollections.append(QString::number(col));
}
diff --git a/src/server/handlerhelper.cpp b/src/server/handlerhelper.cpp
index f25ce5a..2ff5fa3 100644
--- a/src/server/handlerhelper.cpp
+++ b/src/server/handlerhelper.cpp
@@ -247,6 +247,7 @@ Protocol::FetchRelationsResponse HandlerHelper::fetchRelationsResponse(const Rel
Flag::List HandlerHelper::resolveFlags(const QSet<QByteArray> &flagNames)
{
Flag::List flagList;
+ flagList.reserve(flagNames.size());
Q_FOREACH (const QByteArray &flagName, flagNames) {
Flag flag = Flag::retrieveByName(QString::fromUtf8(flagName));
if (!flag.isValid()) {
diff --git a/src/server/resourcemanager.cpp b/src/server/resourcemanager.cpp
index fc5fd6e..9c2c30e 100644
--- a/src/server/resourcemanager.cpp
+++ b/src/server/resourcemanager.cpp
@@ -76,7 +76,9 @@ void ResourceManager::removeResourceInstance(const QString &name)
QStringList ResourceManager::resourceInstances() const
{
QStringList result;
- Q_FOREACH (const Resource &res, Resource::retrieveAll()) {
+ const auto resources = Resource::retrieveAll();
+ result.reserve(resources.size());
+ Q_FOREACH (const Resource &res, resources) {
result.append(res.name());
}
return result;
diff --git a/src/server/storage/dbinitializer_p.cpp b/src/server/storage/dbinitializer_p.cpp
index 35b96f4..f44c982 100644
--- a/src/server/storage/dbinitializer_p.cpp
+++ b/src/server/storage/dbinitializer_p.cpp
@@ -242,6 +242,7 @@ QString DbInitializerPostgreSql::sqlType(const QString &type, int size) const
QString DbInitializerPostgreSql::buildCreateTableStatement(const TableDescription &tableDescription) const
{
QStringList columns;
+ columns.reserve(tableDescription.columns.size() + 1);
Q_FOREACH (const ColumnDescription &columnDescription, tableDescription.columns) {
columns.append(buildColumnStatement(columnDescription, tableDescription));
diff --git a/src/server/storage/dbintrospector.cpp b/src/server/storage/dbintrospector.cpp
index 5bcfd8d..4abb696 100644
--- a/src/server/storage/dbintrospector.cpp
+++ b/src/server/storage/dbintrospector.cpp
@@ -78,7 +78,9 @@ bool DbIntrospector::hasColumn(const QString &tableName, const QString &columnNa
if (columns.isEmpty()) {
const QSqlRecord table = m_database.record(tableName);
- for (int i = 0; i < table.count(); ++i) {
+ const int numTables = table.count();
+ columns.reserve(numTables);
+ for (int i = 0; i < numTables; ++i) {
const QSqlField column = table.field(i);
columns.push_back(column.name().toLower());
}
diff --git a/src/server/storage/notificationcollector.cpp b/src/server/storage/notificationcollector.cpp
index 02feb77..1e490cd 100644
--- a/src/server/storage/notificationcollector.cpp
+++ b/src/server/storage/notificationcollector.cpp
@@ -286,11 +286,13 @@ void NotificationCollector::itemNotification(Protocol::ChangeNotification::Opera
msg.setItemParts(parts);
QSet<QByteArray> addedFlagsAndRelations(addedFlags);
+ addedFlagsAndRelations.reserve(addedRelations.size());
Q_FOREACH (const Relation &rel, addedRelations) {
addedFlagsAndRelations << "RELATION " + rel.relationType().name().toLatin1() + " " + QByteArray::number(rel.leftId()) + " " + QByteArray::number(rel.rightId());
}
msg.setAddedFlags(addedFlagsAndRelations);
QSet<QByteArray> removedFlagsAndRelations(removedFlags);
+ removedFlagsAndRelations.reserve(removedRelations.size());
Q_FOREACH (const Relation &rel, removedRelations) {
removedFlagsAndRelations << "RELATION " + rel.relationType().name().toLatin1() + " " + QByteArray::number(rel.leftId()) + " " + QByteArray::number(rel.rightId());
}
diff --git a/src/server/storage/storagedebugger.cpp b/src/server/storage/storagedebugger.cpp
index 6cc18de..07d16fc 100644
--- a/src/server/storage/storagedebugger.cpp
+++ b/src/server/storage/storagedebugger.cpp
@@ -96,7 +96,9 @@ void StorageDebugger::queryExecuted(const QSqlQuery &query, int duration)
if (q.first()) {
const QSqlRecord record = q.record();
QVariantList row;
- for (int i = 0; i < record.count(); ++i) {
+ const int numRecords = record.count();
+ row.reserve(numRecords);
+ for (int i = 0; i < numRecords; ++i) {
row << record.fieldName(i);
}
result << row;
@@ -105,7 +107,9 @@ void StorageDebugger::queryExecuted(const QSqlQuery &query, int duration)
do {
const QSqlRecord record = q.record();
QVariantList row;
- for (int i = 0; i < record.count(); ++i) {
+ const int numRecords = record.count();
+ row.reserve(numRecords);
+ for (int i = 0; i < numRecords; ++i) {
row << record.value(i);
}
result << row;
diff --git a/src/server/storagejanitor.cpp b/src/server/storagejanitor.cpp
index bb89c1d..0b7f529 100644
--- a/src/server/storagejanitor.cpp
+++ b/src/server/storagejanitor.cpp
@@ -221,6 +221,7 @@ void StorageJanitor::findOrphanedResources()
const Resource::List orphanResources = qbres.result();
if (orphanResources.size() > 0) {
QStringList resourceNames;
+ resourceNames.reserve(orphanResources.size());
Q_FOREACH (const Resource &resource, orphanResources) {
resourceNames.append(resource.name());
}