Commit e7450616 authored by Sergio Martins's avatar Sergio Martins

Use QList::reserve(), reduces reallocations.

parent 623808b3
......@@ -72,7 +72,9 @@ bool CollectionSelection::contains(const Akonadi::Collection::Id &id) const
Akonadi::Collection::List CollectionSelection::selectedCollections() const
{
Akonadi::Collection::List selected;
Q_FOREACH (const QModelIndex &idx, d->model->selectedIndexes()) {
const QModelIndexList selectedIndexes = d->model->selectedIndexes();
selected.reserve(selectedIndexes.count());
Q_FOREACH (const QModelIndex &idx, selectedIndexes) {
selected.append(collectionFromIndex(idx));
}
return selected;
......@@ -81,7 +83,9 @@ Akonadi::Collection::List CollectionSelection::selectedCollections() const
QList<Akonadi::Collection::Id> CollectionSelection::selectedCollectionIds() const
{
QList<Akonadi::Collection::Id> selected;
Q_FOREACH (const QModelIndex &idx, d->model->selectedIndexes()) {
const QModelIndexList selectedIndexes = d->model->selectedIndexes();
selected.reserve(selectedIndexes.count());
Q_FOREACH (const QModelIndex &idx, selectedIndexes) {
selected.append(collectionIdFromIndex(idx));
}
return selected;
......
......@@ -164,6 +164,7 @@ void EventArchiver::deleteIncidences(Akonadi::IncidenceChanger *changer,
QStringList incidenceStrs;
Akonadi::Item::List::ConstIterator it;
Akonadi::Item::List::ConstIterator end(items.constEnd());
incidenceStrs.reserve(items.count());
for (it = items.constBegin(); it != end; ++it) {
incidenceStrs.append(CalendarSupport::incidence(*it)->summary());
}
......@@ -232,6 +233,7 @@ void EventArchiver::archiveIncidences(const Akonadi::ETMCalendar::Ptr &calendar,
// remain. This is not really efficient, but there is no other easy way.
QStringList uids;
Incidence::List allIncidences = archiveCalendar->rawIncidences();
uids.reserve(incidences.count());
foreach (const KCalCore::Incidence::Ptr &incidence, incidences) {
uids.append(incidence->uid());
}
......
......@@ -241,13 +241,16 @@ QStringList KCalPrefs::allEmails()
QStringList KCalPrefs::fullEmails()
{
QStringList fullEmails;
// The user name and email from the config dialog:
fullEmails << QString::fromUtf8("%1 <%2>").arg(fullName()).arg(email());
QStringList::Iterator it;
// Grab emails from the email identities
KIdentityManagement::IdentityManager *idmanager = CalendarSupport::identityManager();
QStringList lst = idmanager->identities();
fullEmails.reserve(1 + mAdditionalMails.count() + lst.count());
// The user name and email from the config dialog:
fullEmails << QString::fromUtf8("%1 <%2>").arg(fullName()).arg(email());
QStringList::Iterator it;
KIdentityManagement::IdentityManager::ConstIterator it1;
for (it1 = idmanager->begin(); it1 != idmanager->end(); ++it1) {
fullEmails << (*it1).fullEmailAddr();
......
......@@ -344,6 +344,7 @@ void CalPrintIncidence::print(QPainter &p, int width, int height)
QStringList alarmStrings;
KCalCore::Alarm::List::ConstIterator it;
alarmStrings.reserve(alarms.count());
for (it = alarms.constBegin(); it != alarms.constEnd(); ++it) {
KCalCore::Alarm::Ptr alarm = *it;
......
......@@ -979,6 +979,7 @@ void CalPrintPluginBase::drawAgendaDayBox(QPainter &p, const KCalCore::Event::Li
continue;
}
QList<KDateTime> times = event->startDateTimesForDate(qd);
cells.reserve(times.count());
for (QList<KDateTime>::ConstIterator it = times.constBegin();
it != times.constEnd(); ++it) {
cells.append(new PrintCellItem(event, (*it), event->endDateForStart(*it)));
......@@ -2080,6 +2081,7 @@ void CalPrintPluginBase::drawTodo(int &count, const KCalCore::Todo::Ptr &todo, Q
KCalCore::Todo::List sl = mCalendar->sortTodos(&t, sortField, sortDir);
#else
KCalCore::Todo::List tl;
tl.reserve(t.count());
foreach (const KCalCore::Todo::Ptr &todo, t) {
tl.append(todo);
}
......
......@@ -401,7 +401,9 @@ KCalCore::Todo::List CalendarSupport::todos(const QMimeData *mimeData,
#ifndef QT_NO_DRAGANDDROP
KCalCore::Calendar::Ptr cal(KCalUtils::DndFactory::createDropCalendar(mimeData, spec));
if (cal) {
Q_FOREACH (const KCalCore::Todo::Ptr &i, cal->todos()) {
const KCalCore::Todo::List calTodos = cal->todos();
todos.reserve(calTodos.count());
Q_FOREACH (const KCalCore::Todo::Ptr &i, calTodos) {
todos.push_back(KCalCore::Todo::Ptr(i->clone()));
}
}
......@@ -419,6 +421,7 @@ KCalCore::Incidence::List CalendarSupport::incidences(const QMimeData *mimeData,
KCalCore::Calendar::Ptr cal(KCalUtils::DndFactory::createDropCalendar(mimeData, spec));
if (cal) {
KCalCore::Incidence::List calIncidences = cal->incidences();
incidences.reserve(calIncidences.count());
Q_FOREACH (const KCalCore::Incidence::Ptr &i, calIncidences) {
incidences.push_back(KCalCore::Incidence::Ptr(i->clone()));
}
......@@ -527,6 +530,7 @@ Akonadi::Collection::Id CalendarSupport::collectionIdFromIndex(const QModelIndex
Akonadi::Collection::List CalendarSupport::collectionsFromIndexes(const QModelIndexList &indexes)
{
Akonadi::Collection::List l;
l.reserve(indexes.count());
Q_FOREACH (const QModelIndex &idx, indexes) {
l.push_back(collectionFromIndex(idx));
}
......@@ -714,7 +718,8 @@ QStringList CalendarSupport::holiday(const QDate &date)
const HolidayRegion holidays(KCalPrefs::instance()->mHolidays);
const Holiday::List list = holidays.holidays(date);
const int listCount(list.count());
const int listCount = list.count();
hdays.reserve(listCount);
for (int i = 0; i < listCount; ++i) {
hdays.append(list.at(i).text());
}
......
......@@ -389,6 +389,7 @@ QList<QDate> AgendaView::Private::generateDateList(const QDate &start, const QDa
if (start.isValid() && end.isValid() && end >= start &&
start.daysTo(end) < AgendaView::MAX_DAY_COUNT) {
QDate date = start;
list.reserve(start.daysTo(end) + 1);
while (date <= end) {
list.append(date);
date = date.addDays(1);
......
......@@ -202,7 +202,9 @@ void TimeScaleConfigDialog::down()
QStringList TimeScaleConfigDialog::zones()
{
QStringList list;
for (int i = 0; i < listWidget->count(); ++i) {
const int count = listWidget->count();
list.reserve(count);
for (int i = 0; i < count; ++i) {
list << listWidget->item(i)->data(TimeZoneNameRole).toString();
}
return list;
......
......@@ -105,6 +105,7 @@ void JournalDateView::addJournal(const Akonadi::Item &j)
Akonadi::Item::List JournalDateView::journals() const
{
Akonadi::Item::List l;
l.reserve(mEntries.count());
Q_FOREACH (const JournalFrame *const i, mEntries) {
l.push_back(i->journal());
}
......
......@@ -112,7 +112,9 @@ void MonthViewPrivate::moveStartDate(int weeks, int months)
#ifndef KDEPIM_MOBILE_UI
KCalCore::DateList dateList;
QDate d = start.date();
while (d <= end.date()) {
const QDate e = end.date();
dateList.reserve(d.daysTo(e) + 1);
while (d <= e) {
dateList.append(d);
d = d.addDays(1);
}
......
......@@ -512,6 +512,7 @@ Akonadi::Item::List TodoView::selectedIncidences() const
{
Akonadi::Item::List ret;
const QModelIndexList selection = mView->selectionModel()->selectedRows();
ret.reserve(selection.count());
Q_FOREACH (const QModelIndex &mi, selection) {
ret << mi.data(TodoModel::TodoRole).value<Akonadi::Item>();
}
......@@ -535,7 +536,11 @@ void TodoView::saveLayout(KConfig *config, const QString &group) const
QVariantList columnVisibility;
QVariantList columnOrder;
QVariantList columnWidths;
for (int i = 0; i < header->count(); ++i) {
const int headerCount = header->count();
columnVisibility.reserve(headerCount);
columnWidths.reserve(headerCount);
columnOrder.reserve(headerCount);
for (int i = 0; i < headerCount; ++i) {
columnVisibility << QVariant(!mView->isColumnHidden(i));
columnWidths << QVariant(header->sectionSize(i));
columnOrder << QVariant(header->visualIndex(i));
......
......@@ -138,6 +138,7 @@ void AlarmDialog::load(const KCalCore::Alarm::Ptr &alarm)
mUi->mTypeCombo->setCurrentIndex(3);
KCalCore::Person::List addresses = alarm->mailAddresses();
QStringList add;
add.reserve(addresses.count());
for (KCalCore::Person::List::ConstIterator it = addresses.constBegin();
it != addresses.constEnd(); ++it) {
add << (*it)->fullName();
......@@ -214,6 +215,7 @@ void AlarmDialog::save(const KCalCore::Alarm::Ptr &alarm) const
} else if (mUi->mTypeCombo->currentIndex() == 3) { // Email
QStringList addresses = KEmailAddress::splitAddressList(mUi->mEmailAddress->text());
KCalCore::Person::List add;
add.reserve(addresses.count());
for (QStringList::Iterator it = addresses.begin(); it != addresses.end(); ++it) {
add << KCalCore::Person::fromFullName(*it);
}
......
......@@ -405,6 +405,8 @@ void IncidenceAttachment::handlePasteOrDrop(const QMimeData *mimeData)
if (KContacts::VCardDrag::canDecode(mimeData)) {
KContacts::Addressee::List addressees;
KContacts::VCardDrag::fromMimeData(mimeData, addressees);
urls.reserve(addressees.count());
labels.reserve(addressees.count());
for (KContacts::Addressee::List::ConstIterator it = addressees.constBegin();
it != addressees.constEnd(); ++it) {
urls.append(QString(QLatin1String("uid:") + (*it).uid()));
......@@ -425,6 +427,7 @@ void IncidenceAttachment::handlePasteOrDrop(const QMimeData *mimeData)
} else if (mimeData->hasText()) {
QString text = mimeData->text();
QStringList lst = text.split('\n', QString::SkipEmptyParts);
urls.reserve(lst.count());
for (QStringList::ConstIterator it = lst.constBegin(); it != lst.constEnd(); ++it) {
urls.append(*it);
}
......
......@@ -229,7 +229,9 @@ void IncidenceAttendee::load(const KCalCore::Incidence::Ptr &incidence)
}
KCalCore::Attendee::List attendees;
foreach (const KCalCore::Attendee::Ptr &a, incidence->attendees()) {
const KCalCore::Attendee::List incidenceAttendees = incidence->attendees();
attendees.reserve(incidenceAttendees.count());
foreach (const KCalCore::Attendee::Ptr &a, incidenceAttendees) {
attendees << KCalCore::Attendee::Ptr(new KCalCore::Attendee(*a));
}
......
......@@ -97,6 +97,7 @@ void IncidenceCategories::save(Akonadi::Item &item)
QStringList IncidenceCategories::categories() const
{
QStringList list;
list.reserve(mSelectedTags.count());
Q_FOREACH (const Akonadi::Tag &tag, mSelectedTags) {
list << tag.name();
}
......
......@@ -215,7 +215,9 @@ void ResourceManagement::showDetails(const KLDAP::LdapObject &obj, const KLDAP::
continue;
}
QStringList list;
foreach (const QByteArray &value, obj.attributes().value(key)) {
const QList<QByteArray> values = obj.attributes().value(key);
list.reserve(values.count());
foreach (const QByteArray &value, values) {
list << QString::fromUtf8(value);
}
mUi->formDetails->addRow(translateLDAPAttributeForDisplay(key), new QLabel(list.join("\n")));
......@@ -231,7 +233,8 @@ void ResourceManagement::showDetails(const KLDAP::LdapObject &obj, const KLDAP::
void ResourceManagement::slotLayoutChanged()
{
for (int i = 1; i < mUi->treeResults->model()->columnCount(QModelIndex()); ++i) {
const int columnCount = mUi->treeResults->model()->columnCount(QModelIndex());
for (int i = 1; i < columnCount; ++i) {
mUi->treeResults->setColumnHidden(i, true);
}
}
......@@ -255,7 +258,9 @@ void ResourceManagement::slotOwnerSearchFinished()
continue;
}
QStringList list;
foreach (const QByteArray &value, obj.attributes().value(key)) {
const QList<QByteArray> values = obj.attributes().value(key);
list.reserve(values.count());
foreach (const QByteArray &value, values) {
list << QString::fromUtf8(value);
}
mUi->formOwner->addRow(translateLDAPAttributeForDisplay(key), new QLabel(list.join(QStringLiteral("\n"))));
......
......@@ -428,6 +428,7 @@ void AlarmDialog::dismissAll()
void AlarmDialog::dismiss(ReminderList selections)
{
QList<Akonadi::Item::Id> ids;
ids.reserve(selections.count());
for (ReminderList::Iterator it = selections.begin(); it != selections.end(); ++it) {
qCDebug(KOALARMCLIENT_LOG) << "removing " << CalendarSupport::incidence((*it)->mIncidence)->summary();
if (mIncidenceTree->itemBelow(*it)) {
......@@ -651,6 +652,7 @@ void AlarmDialog::eventNotification()
} else {
const Person::List addresses = alarm->mailAddresses();
QStringList add;
add.reserve(addresses.count());
for (Person::List::ConstIterator it = addresses.constBegin();
it != addresses.constEnd(); ++it) {
add << (*it)->fullName();
......@@ -873,7 +875,7 @@ KDateTime AlarmDialog::triggerDateForIncidence(const Incidence::Ptr &incidence,
return result;
}
Alarm::Ptr alarm = incidence->alarms().first();
Alarm::Ptr alarm = incidence->alarms().at(0);
if (incidence->recurs()) {
result = incidence->recurrence()->getNextDateTime(
......
......@@ -282,16 +282,17 @@ QStringList KOAlarmClient::dumpAlarms()
const KDateTime end = start.addDays(1).addSecs(-1);
QStringList lst;
const Alarm::List alarms = mCalendar->alarms(start, end);
lst.reserve(1 + (alarms.isEmpty() ? 1 : alarms.count()));
// Don't translate, this is for debugging purposes.
lst << QLatin1String("AlarmDeamon::dumpAlarms() from ") + start.toString() + QLatin1String(" to ") +
end.toString();
Alarm::List alarms = mCalendar->alarms(start, end);
if (alarms.isEmpty()) {
lst << QLatin1String("No alarm found.");
} else {
foreach (Alarm::Ptr a, alarms) {
foreach (const Alarm::Ptr &a, alarms) {
const Incidence::Ptr parentIncidence = mCalendar->incidence(a->parentUid());
lst << QLatin1String(" ") + parentIncidence->summary() + QLatin1String(" (") + a->time().toString() + QLatin1Char(')');
}
......
......@@ -186,6 +186,7 @@ QStringList extractEmailAndNormalize(const QString &email)
{
const QStringList splittedEmail = KEmailAddress::splitAddressList(email);
QStringList normalizedEmail;
normalizedEmail.reserve(splittedEmail.count());
Q_FOREACH (const QString &email, splittedEmail) {
const QString str = KEmailAddress::extractEmailAddress(KEmailAddress::normalizeAddressesAndEncodeIdn(email));
normalizedEmail << str;
......
......@@ -1436,7 +1436,8 @@ void ActionManager::downloadNewStuff()
} else {
QStringList eventSummaries;
KCalCore::Event::List events = calendar()->events();
foreach (KCalCore::Event::Ptr event, events) {
eventSummaries.reserve(events.count());
foreach (const KCalCore::Event::Ptr &event, events) {
eventSummaries.append(event->summary());
}
......
......@@ -520,6 +520,7 @@ void CalendarView::writeFilterSettings(KConfig *config)
group.deleteGroup();
}
filterList.reserve(mFilters.count());
foreach (KCalCore::CalFilter *filter, mFilters) {
filterList << filter->name();
KConfigGroup filterConfig(config, QLatin1String("Filter_") + filter->name());
......
......@@ -86,9 +86,9 @@ void DateNavigator::selectDates(const QDate &d, int count,
const QDate &preferredMonth)
{
KCalCore::DateList dates;
dates.reserve(count);
int i;
for (i = 0; i < count; ++i) {
for (int i = 0; i < count; ++i) {
dates.append(d.addDays(i));
}
......
......@@ -231,7 +231,9 @@ void FilterEdit::bNewPressed()
mDetailsFrame->setEnabled(true);
saveChanges();
QStringList filterNames;
for (int i = 0; i < mRulesList->count(); ++i) {
const int numRules = mRulesList->count();
filterNames.reserve(numRules);
for (int i = 0; i < numRules; ++i) {
filterNames << mRulesList->item(i)->text();
}
QString newFilterName;
......
......@@ -566,6 +566,7 @@ void KODayMatrix::mouseReleaseEvent(QMouseEvent *e)
if (mSelStart < 0) {
mSelStart = 0;
}
daylist.reserve(mSelEnd - mSelStart + 1);
for (int i = mSelStart; i <= mSelEnd; ++i) {
daylist.append(mDays[i]);
}
......
......@@ -172,8 +172,9 @@ SummaryEventInfo::List SummaryEventInfo::eventsForRange(const QDate &start, cons
SummaryEventInfo::List eventInfoList;
KCalCore::Event::Ptr ev;
KCalCore::Event::List::ConstIterator itEnd = events.constEnd();
for (KCalCore::Event::List::ConstIterator it = events.constBegin(); it != itEnd; ++it) {
eventInfoList.reserve(events.count());
auto itEnd = events.constEnd();
for (auto it = events.constBegin(); it != itEnd; ++it) {
ev = *it;
// Count number of days remaining in multiday event
int span = 1;
......
......@@ -145,9 +145,10 @@ void NavigatorBar::selectMonthFromMenu()
int months = calSys->monthsInYear(mDate);
QMenu *menu = new QMenu(mMonth);
QList<QAction *>act;
QList<QAction *> act;
QAction *activateAction = Q_NULLPTR;
act.reserve(months);
for (int i = 1; i <= months; ++i) {
QAction *monthAction = menu->addAction(calSys->monthName(i, year));
act.append(monthAction);
......@@ -185,7 +186,8 @@ void NavigatorBar::selectYearFromMenu()
int minYear = year - (years / 3);
QMenu *menu = new QMenu(mYear);
QList<QAction *>act;
QList<QAction *> act;
act.reserve(years);
QString yearStr;
QAction *activateAction = Q_NULLPTR;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment