summaryrefslogtreecommitdiffstats
path: root/src/printsupport/kernel
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-12-23 00:15:30 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-12-23 09:38:38 +0000
commitb78097b22d11a7279551709b28ef49d403407449 (patch)
treedf23177fb98e02da88b8be66293e0f8856f38a15 /src/printsupport/kernel
parent2d4295f16761a0e47b5218bbb1db5c14d16ce4fe (diff)
QtPrintSupport: eradicate all Q_FOREACH loops
Saves more than 2KiB in text size on optimized GCC 4.9 Linux AMD64 builds, iow: ~0.5% of the total library size. Change-Id: I84e1dc208da13eefdf1573c9b7ac7c9d76a7f5c7 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/printsupport/kernel')
-rw-r--r--src/printsupport/kernel/qplatformprintdevice.cpp10
-rw-r--r--src/printsupport/kernel/qprintengine_win.cpp8
-rw-r--r--src/printsupport/kernel/qprinter.cpp3
-rw-r--r--src/printsupport/kernel/qprinterinfo.cpp8
4 files changed, 17 insertions, 12 deletions
diff --git a/src/printsupport/kernel/qplatformprintdevice.cpp b/src/printsupport/kernel/qplatformprintdevice.cpp
index 6385f58aa1..507c66d895 100644
--- a/src/printsupport/kernel/qplatformprintdevice.cpp
+++ b/src/printsupport/kernel/qplatformprintdevice.cpp
@@ -168,7 +168,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) con
// e.g. Windows defines DMPAPER_11X17 and DMPAPER_TABLOID with names "11x17" and "Tabloid", but both
// map to QPageSize::Tabloid / PPD Key "Tabloid" / ANSI B Tabloid
if (pageSize.id() != QPageSize::Custom) {
- foreach (const QPageSize &ps, m_pageSizes) {
+ for (const QPageSize &ps : m_pageSizes) {
if (ps.id() == pageSize.id() && ps.name() == pageSize.name())
return ps;
}
@@ -176,7 +176,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) con
// Next try match on id only if not custom
if (pageSize.id() != QPageSize::Custom) {
- foreach (const QPageSize &ps, m_pageSizes) {
+ for (const QPageSize &ps : m_pageSizes) {
if (ps.id() == pageSize.id())
return ps;
}
@@ -191,7 +191,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSize
if (!m_havePageSizes)
loadPageSizes();
- foreach (const QPageSize &ps, m_pageSizes) {
+ for (const QPageSize &ps : m_pageSizes) {
if (ps.id() == pageSizeId)
return ps;
}
@@ -205,7 +205,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QString &pageName) const
if (!m_havePageSizes)
loadPageSizes();
- foreach (const QPageSize &ps, m_pageSizes) {
+ for (const QPageSize &ps : m_pageSizes) {
if (ps.name() == pageName)
return ps;
}
@@ -234,7 +234,7 @@ QPageSize QPlatformPrintDevice::supportedPageSize(const QSizeF &size, QPageSize:
QPageSize QPlatformPrintDevice::supportedPageSizeMatch(const QPageSize &pageSize) const
{
// Try to find a supported page size based on point size
- foreach (const QPageSize &ps, m_pageSizes) {
+ for (const QPageSize &ps : m_pageSizes) {
if (ps.sizePoints() == pageSize.sizePoints())
return ps;
}
diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp
index 00a8ca7c98..06a1e371bf 100644
--- a/src/printsupport/kernel/qprintengine_win.cpp
+++ b/src/printsupport/kernel/qprintengine_win.cpp
@@ -1463,7 +1463,9 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const
case PPK_SupportedResolutions: {
QList<QVariant> list;
- foreach (int resolution, d->m_printDevice.supportedResolutions())
+ const auto resolutions = d->m_printDevice.supportedResolutions();
+ list.reserve(resolutions.size());
+ for (int resolution : resolutions)
list << resolution;
value = list;
break;
@@ -1475,7 +1477,9 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const
case PPK_PaperSources: {
QList<QVariant> out;
- foreach (const QPrint::InputSlot inputSlot, d->m_printDevice.supportedInputSlots())
+ const auto inputSlots = d->m_printDevice.supportedInputSlots();
+ out.reserve(inputSlots.size());
+ for (const QPrint::InputSlot inputSlot : inputSlots)
out << QVariant(inputSlot.id == QPrint::CustomInputSlot ? inputSlot.windowsId : int(inputSlot.id));
value = out;
break;
diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp
index 734691d504..7f08bdb3e9 100644
--- a/src/printsupport/kernel/qprinter.cpp
+++ b/src/printsupport/kernel/qprinter.cpp
@@ -160,7 +160,8 @@ void QPrinterPrivate::changeEngines(QPrinter::OutputFormat format, const QPrinte
initEngines(format, printer);
if (oldPrintEngine) {
- foreach (QPrintEngine::PrintEnginePropertyKey key, m_properties) {
+ const auto properties = m_properties; // take a copy: setProperty() below modifies m_properties
+ for (const auto &key : properties) {
QVariant prop;
// PPK_NumberOfCopies need special treatmeant since it in most cases
// will return 1, disregarding the actual value that was set
diff --git a/src/printsupport/kernel/qprinterinfo.cpp b/src/printsupport/kernel/qprinterinfo.cpp
index 1be574891b..7ccd7d1fea 100644
--- a/src/printsupport/kernel/qprinterinfo.cpp
+++ b/src/printsupport/kernel/qprinterinfo.cpp
@@ -318,7 +318,7 @@ QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
QList<QPrinter::PaperSize> list;
const QList<QPageSize> supportedPageSizes = d->m_printDevice.supportedPageSizes();
list.reserve(supportedPageSizes.size());
- foreach (const QPageSize &pageSize, supportedPageSizes)
+ for (const QPageSize &pageSize : supportedPageSizes)
list.append(QPrinter::PaperSize(pageSize.id()));
return list;
}
@@ -340,7 +340,7 @@ QList<QPair<QString, QSizeF> > QPrinterInfo::supportedSizesWithNames() const
QList<QPair<QString, QSizeF> > list;
const QList<QPageSize> supportedPageSizes = d->m_printDevice.supportedPageSizes();
list.reserve(supportedPageSizes.size());
- foreach (const QPageSize &pageSize, supportedPageSizes)
+ for (const QPageSize &pageSize : supportedPageSizes)
list.append(qMakePair(pageSize.name(), pageSize.size(QPageSize::Millimeter)));
return list;
}
@@ -382,7 +382,7 @@ QList<QPrinter::DuplexMode> QPrinterInfo::supportedDuplexModes() const
QList<QPrinter::DuplexMode> list;
const QList<QPrint::DuplexMode> supportedDuplexModes = d->m_printDevice.supportedDuplexModes();
list.reserve(supportedDuplexModes.size());
- foreach (QPrint::DuplexMode mode, supportedDuplexModes)
+ for (QPrint::DuplexMode mode : supportedDuplexModes)
list << QPrinter::DuplexMode(mode);
return list;
}
@@ -424,7 +424,7 @@ QList<QPrinterInfo> QPrinterInfo::availablePrinters()
if (ps) {
const QStringList availablePrintDeviceIds = ps->availablePrintDeviceIds();
list.reserve(availablePrintDeviceIds.size());
- foreach (const QString &id, availablePrintDeviceIds)
+ for (const QString &id : availablePrintDeviceIds)
list.append(QPrinterInfo(id));
}
return list;