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>
This commit is contained in:
parent
56fbcfd2b7
commit
46d257b19d
@ -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");
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user