From 507b6b3e4bcef3ef280944f3956b7f32ed86985b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Martins?= Date: Tue, 23 Jun 2015 16:18:12 +0100 Subject: Use QList::reserve(), reduces reallocations Change-Id: I9f218bdd65a97ad9c867b695f3ba27ab64a54d2a Reviewed-by: Marc Mutz --- src/printsupport/kernel/qprinterinfo.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/printsupport/kernel/qprinterinfo.cpp') diff --git a/src/printsupport/kernel/qprinterinfo.cpp b/src/printsupport/kernel/qprinterinfo.cpp index ad488a10ed..1be574891b 100644 --- a/src/printsupport/kernel/qprinterinfo.cpp +++ b/src/printsupport/kernel/qprinterinfo.cpp @@ -316,7 +316,9 @@ QList QPrinterInfo::supportedPaperSizes() const { Q_D(const QPrinterInfo); QList list; - foreach (const QPageSize &pageSize, d->m_printDevice.supportedPageSizes()) + const QList supportedPageSizes = d->m_printDevice.supportedPageSizes(); + list.reserve(supportedPageSizes.size()); + foreach (const QPageSize &pageSize, supportedPageSizes) list.append(QPrinter::PaperSize(pageSize.id())); return list; } @@ -336,7 +338,9 @@ QList > QPrinterInfo::supportedSizesWithNames() const { Q_D(const QPrinterInfo); QList > list; - foreach (const QPageSize &pageSize, d->m_printDevice.supportedPageSizes()) + const QList supportedPageSizes = d->m_printDevice.supportedPageSizes(); + list.reserve(supportedPageSizes.size()); + foreach (const QPageSize &pageSize, supportedPageSizes) list.append(qMakePair(pageSize.name(), pageSize.size(QPageSize::Millimeter))); return list; } @@ -376,7 +380,9 @@ QList QPrinterInfo::supportedDuplexModes() const { Q_D(const QPrinterInfo); QList list; - foreach (QPrint::DuplexMode mode, d->m_printDevice.supportedDuplexModes()) + const QList supportedDuplexModes = d->m_printDevice.supportedDuplexModes(); + list.reserve(supportedDuplexModes.size()); + foreach (QPrint::DuplexMode mode, supportedDuplexModes) list << QPrinter::DuplexMode(mode); return list; } @@ -416,7 +422,9 @@ QList QPrinterInfo::availablePrinters() QList list; QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get(); if (ps) { - foreach (const QString &id, ps->availablePrintDeviceIds()) + const QStringList availablePrintDeviceIds = ps->availablePrintDeviceIds(); + list.reserve(availablePrintDeviceIds.size()); + foreach (const QString &id, availablePrintDeviceIds) list.append(QPrinterInfo(id)); } return list; -- cgit v1.2.3