diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-06-08 00:17:53 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-07-12 06:56:02 +0200 |
commit | 46d257b19d677e4e4b2a24624716af2207dd9759 (patch) | |
tree | 0abd15a3541be62c21c1c4a6b56696dae2d5f41d | |
parent | 56fbcfd2b78bc62eca953a5cd3af831a8964e9e1 (diff) |
QPdfEngine: replace a QHash with a C array
The mapping is completely static and the key is the index, so just use
a const char array. The only twist here is that to avoid relocations,
we use an array of const char[4] instead of const char*[].
Change-Id: I001b4db833f14e000676125f6f1be4484d996e0b
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
-rw-r--r-- | src/gui/painting/qpdf.cpp | 12 | ||||
-rw-r--r-- | src/gui/painting/qpdf_p.h | 2 |
2 files changed, 8 insertions, 6 deletions
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 25d488961c..f560e1f0f0 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -1570,12 +1570,14 @@ void QPdfEnginePrivate::writeHeader() { addXrefEntry(0,false); - static const QHash<QPdfEngine::PdfVersion, const char *> mapping { - {QPdfEngine::Version_1_4, "1.4"}, - {QPdfEngine::Version_A1b, "1.4"}, - {QPdfEngine::Version_1_6, "1.6"} + // Keep in sync with QPdfEngine::PdfVersion! + static const char mapping[][4] = { + "1.4", // Version_1_4 + "1.4", // Version_A1b + "1.6", // Version_1_6 }; - const char *verStr = mapping.value(pdfVersion, "1.4"); + static const size_t numMappings = sizeof mapping / sizeof *mapping; + const char *verStr = mapping[size_t(pdfVersion) < numMappings ? pdfVersion : 0]; xprintf("%%PDF-%s\n", verStr); xprintf("%%\303\242\303\243\n"); diff --git a/src/gui/painting/qpdf_p.h b/src/gui/painting/qpdf_p.h index e5649eb9dc..89e549614a 100644 --- a/src/gui/painting/qpdf_p.h +++ b/src/gui/painting/qpdf_p.h @@ -168,7 +168,7 @@ class Q_GUI_EXPORT QPdfEngine : public QPaintEngine Q_DECLARE_PRIVATE(QPdfEngine) friend class QPdfWriter; public: - // keep in sync with QPagedPaintDevice::PdfVersion! + // keep in sync with QPagedPaintDevice::PdfVersion and QPdfEnginePrivate::writeHeader()::mapping! enum PdfVersion { Version_1_4, |