From 5cb54cb5ebae99fab121061e25e26eec3056203a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 12 Dec 2017 12:44:02 +0100 Subject: [PATCH 44/54] QPlatformPrintDevice: use QVector, not QList in the API QPlaformPrintDevice uses QVector to store, but QList in the getters to retrieve these data. Port API from QList to QVector to avoid conversion between the two containers on every access. Saves almost 4KiB in text size (another 0.9% of QtPrintSupport). Change-Id: If33df141b87753803c45d9f4dae501a68abe49af Reviewed-by: Lars Knoll --- src/printsupport/kernel/qplatformprintdevice.cpp | 16 ++++++++-------- src/printsupport/kernel/qplatformprintdevice.h | 8 ++++---- src/printsupport/kernel/qprintdevice.cpp | 16 ++++++++-------- src/printsupport/kernel/qprintdevice_p.h | 8 ++++---- src/printsupport/kernel/qprintengine_win.cpp | 8 ++++---- src/printsupport/kernel/qprinterinfo.cpp | 2 +- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/printsupport/kernel/qplatformprintdevice.cpp b/src/printsupport/kernel/qplatformprintdevice.cpp index 82bddedb1b..2f76156a91 100644 --- a/src/printsupport/kernel/qplatformprintdevice.cpp +++ b/src/printsupport/kernel/qplatformprintdevice.cpp @@ -313,11 +313,11 @@ QPrint::InputSlot QPlatformPrintDevice::defaultInputSlot() const return input; } -QList QPlatformPrintDevice::supportedInputSlots() const +QVector QPlatformPrintDevice::supportedInputSlots() const { if (!m_haveInputSlots) loadInputSlots(); - return m_inputSlots.toList(); + return m_inputSlots; } void QPlatformPrintDevice::loadOutputBins() const @@ -337,11 +337,11 @@ QPrint::OutputBin QPlatformPrintDevice::defaultOutputBin() const return output; } -QList QPlatformPrintDevice::supportedOutputBins() const +QVector QPlatformPrintDevice::supportedOutputBins() const { if (!m_haveOutputBins) loadOutputBins(); - return m_outputBins.toList(); + return m_outputBins; } void QPlatformPrintDevice::loadDuplexModes() const @@ -353,11 +353,11 @@ QPrint::DuplexMode QPlatformPrintDevice::defaultDuplexMode() const return QPrint::DuplexNone; } -QList QPlatformPrintDevice::supportedDuplexModes() const +QVector QPlatformPrintDevice::supportedDuplexModes() const { if (!m_haveDuplexModes) loadDuplexModes(); - return m_duplexModes.toList(); + return m_duplexModes; } void QPlatformPrintDevice::loadColorModes() const @@ -369,11 +369,11 @@ QPrint::ColorMode QPlatformPrintDevice::defaultColorMode() const return QPrint::GrayScale; } -QList QPlatformPrintDevice::supportedColorModes() const +QVector QPlatformPrintDevice::supportedColorModes() const { if (!m_haveColorModes) loadColorModes(); - return m_colorModes.toList(); + return m_colorModes; } #ifndef QT_NO_MIMETYPE diff --git a/src/printsupport/kernel/qplatformprintdevice.h b/src/printsupport/kernel/qplatformprintdevice.h index 1cac009660..8af76464b5 100644 --- a/src/printsupport/kernel/qplatformprintdevice.h +++ b/src/printsupport/kernel/qplatformprintdevice.h @@ -110,16 +110,16 @@ public: virtual QList supportedResolutions() const; virtual QPrint::InputSlot defaultInputSlot() const; - virtual QList supportedInputSlots() const; + virtual QVector supportedInputSlots() const; virtual QPrint::OutputBin defaultOutputBin() const; - virtual QList supportedOutputBins() const; + virtual QVector supportedOutputBins() const; virtual QPrint::DuplexMode defaultDuplexMode() const; - virtual QList supportedDuplexModes() const; + virtual QVector supportedDuplexModes() const; virtual QPrint::ColorMode defaultColorMode() const; - virtual QList supportedColorModes() const; + virtual QVector supportedColorModes() const; virtual QVariant property(QPrintDevice::PrintDevicePropertyKey key) const; virtual bool setProperty(QPrintDevice::PrintDevicePropertyKey key, const QVariant &value); diff --git a/src/printsupport/kernel/qprintdevice.cpp b/src/printsupport/kernel/qprintdevice.cpp index 7096f5a2f6..2bc6906364 100644 --- a/src/printsupport/kernel/qprintdevice.cpp +++ b/src/printsupport/kernel/qprintdevice.cpp @@ -210,9 +210,9 @@ QPrint::InputSlot QPrintDevice::defaultInputSlot() const return isValid() ? d->defaultInputSlot() : QPrint::InputSlot(); } -QList QPrintDevice::supportedInputSlots() const +QVector QPrintDevice::supportedInputSlots() const { - return isValid() ? d->supportedInputSlots() : QList(); + return isValid() ? d->supportedInputSlots() : QVector{}; } QPrint::OutputBin QPrintDevice::defaultOutputBin() const @@ -220,9 +220,9 @@ QPrint::OutputBin QPrintDevice::defaultOutputBin() const return isValid() ? d->defaultOutputBin() : QPrint::OutputBin(); } -QList QPrintDevice::supportedOutputBins() const +QVector QPrintDevice::supportedOutputBins() const { - return isValid() ? d->supportedOutputBins() : QList(); + return isValid() ? d->supportedOutputBins() : QVector{}; } QPrint::DuplexMode QPrintDevice::defaultDuplexMode() const @@ -230,9 +230,9 @@ QPrint::DuplexMode QPrintDevice::defaultDuplexMode() const return isValid() ? d->defaultDuplexMode() : QPrint::DuplexNone; } -QList QPrintDevice::supportedDuplexModes() const +QVector QPrintDevice::supportedDuplexModes() const { - return isValid() ? d->supportedDuplexModes() : QList(); + return isValid() ? d->supportedDuplexModes() : QVector{}; } QPrint::ColorMode QPrintDevice::defaultColorMode() const @@ -240,9 +240,9 @@ QPrint::ColorMode QPrintDevice::defaultColorMode() const return isValid() ? d->defaultColorMode() : QPrint::GrayScale; } -QList QPrintDevice::supportedColorModes() const +QVector QPrintDevice::supportedColorModes() const { - return isValid() ? d->supportedColorModes() : QList(); + return isValid() ? d->supportedColorModes() : QVector{}; } QVariant QPrintDevice::property(PrintDevicePropertyKey key) const diff --git a/src/printsupport/kernel/qprintdevice_p.h b/src/printsupport/kernel/qprintdevice_p.h index 1a26d3afcf..3dff2e54fe 100644 --- a/src/printsupport/kernel/qprintdevice_p.h +++ b/src/printsupport/kernel/qprintdevice_p.h @@ -120,16 +120,16 @@ public: QList supportedResolutions() const; QPrint::InputSlot defaultInputSlot() const; - QList supportedInputSlots() const; + QVector supportedInputSlots() const; QPrint::OutputBin defaultOutputBin() const; - QList supportedOutputBins() const; + QVector supportedOutputBins() const; QPrint::DuplexMode defaultDuplexMode() const; - QList supportedDuplexModes() const; + QVector supportedDuplexModes() const; QPrint::ColorMode defaultColorMode() const; - QList supportedColorModes() const; + QVector supportedColorModes() const; enum PrintDevicePropertyKey { PDPK_CustomBase = 0xff00 diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index e399118cc9..ba234b3aae 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -1024,7 +1024,7 @@ bool QWin32PrintEnginePrivate::resetDC() return hdc != 0; } -static int indexOfId(const QList &inputSlots, QPrint::InputSlotId id) +static int indexOfId(const QVector &inputSlots, QPrint::InputSlotId id) { for (int i = 0; i < inputSlots.size(); ++i) { if (inputSlots.at(i).id == id) @@ -1033,7 +1033,7 @@ static int indexOfId(const QList &inputSlots, QPrint::InputSl return -1; } -static int indexOfWindowsId(const QList &inputSlots, int windowsId) +static int indexOfWindowsId(const QVector &inputSlots, int windowsId) { for (int i = 0; i < inputSlots.size(); ++i) { if (inputSlots.at(i).windowsId == windowsId) @@ -1210,7 +1210,7 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant & case PPK_PaperSource: { if (!d->devMode) break; - const QList inputSlots = d->m_printDevice.supportedInputSlots(); + const auto inputSlots = d->m_printDevice.supportedInputSlots(); const int paperSource = value.toInt(); const int index = paperSource >= DMBIN_USER ? indexOfWindowsId(inputSlots, paperSource) : indexOfId(inputSlots, QPrint::InputSlotId(paperSource)); @@ -1465,7 +1465,7 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const if (d->devMode->dmDefaultSource >= DMBIN_USER) { value = int(d->devMode->dmDefaultSource); } else { - const QList inputSlots = d->m_printDevice.supportedInputSlots(); + const auto inputSlots = d->m_printDevice.supportedInputSlots(); const int index = indexOfWindowsId(inputSlots, d->devMode->dmDefaultSource); value = index >= 0 ? inputSlots.at(index).id : QPrint::Auto; } diff --git a/src/printsupport/kernel/qprinterinfo.cpp b/src/printsupport/kernel/qprinterinfo.cpp index d271e069ad..49a0c9ece4 100644 --- a/src/printsupport/kernel/qprinterinfo.cpp +++ b/src/printsupport/kernel/qprinterinfo.cpp @@ -380,7 +380,7 @@ QList QPrinterInfo::supportedDuplexModes() const { Q_D(const QPrinterInfo); QList list; - const QList supportedDuplexModes = d->m_printDevice.supportedDuplexModes(); + const auto supportedDuplexModes = d->m_printDevice.supportedDuplexModes(); list.reserve(supportedDuplexModes.size()); for (QPrint::DuplexMode mode : supportedDuplexModes) list << QPrinter::DuplexMode(mode); -- 2.15.1