From 0dca6c40e1a66170b68941bc152aec3f29f4fd99 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 16 May 2024 21:32:31 +0200 Subject: [PATCH] PDF: use a map, not a hash, to write the dest roots name tree A PDF name tree is sorted, so just use a sorted data structure for that. This simplifies the code. This work has been kindly sponsored by the QGIS project (https://qgis.org/). Change-Id: Ib08b14aaf79c9180319efe7fefa9e797a4364d54 Reviewed-by: Albert Astals Cid --- src/gui/painting/qpdf.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index 31e8bbdc128..716cf35ee6d 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -23,6 +23,8 @@ #include #include +#include + #ifndef QT_NO_COMPRESS #include #endif @@ -1857,7 +1859,7 @@ void QPdfEnginePrivate::writeDestsRoot() if (destCache.isEmpty()) return; - QHash destObjects; + std::map destObjects; QByteArray xs, ys; for (const DestInfo &destInfo : std::as_const(destCache)) { int destObj = addXrefEntry(-1); @@ -1865,21 +1867,19 @@ void QPdfEnginePrivate::writeDestsRoot() ys.setNum(static_cast(destInfo.coords.y()), 'f'); xprintf("[%d 0 R /XYZ %s %s 0]\n", destInfo.pageObj, xs.constData(), ys.constData()); xprintf("endobj\n"); - destObjects.insert(destInfo.anchor, destObj); + destObjects.insert_or_assign(destInfo.anchor, destObj); } // names destsRoot = addXrefEntry(-1); - QStringList anchors = destObjects.keys(); - anchors.sort(); xprintf("<<\n/Limits ["); - printString(anchors.constFirst()); + printString(destObjects.begin()->first); xprintf(" "); - printString(anchors.constLast()); + printString(destObjects.rbegin()->first); xprintf("]\n/Names [\n"); - for (const QString &anchor : std::as_const(anchors)) { + for (const auto &[anchor, destObject] : destObjects) { printString(anchor); - xprintf(" %d 0 R\n", destObjects[anchor]); + xprintf(" %d 0 R\n", destObject); } xprintf("]\n>>\n" "endobj\n");