From 680b68747e2a8226052397dfaefd62fa5940dfb8 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 19 Jul 2025 18:20:34 +0100 Subject: [PATCH] Refactor linearization hint stream logic in `QPDF_linearization.cc` to simplify buffer handling and streamline compression. --- libqpdf/QPDF_linearization.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc index c853ac7..ce72f98 100644 --- a/libqpdf/QPDF_linearization.cc +++ b/libqpdf/QPDF_linearization.cc @@ -1753,21 +1753,18 @@ QPDF::generateHintStream( // Write the hint stream itself into a compressed memory buffer. Write through a counter so we // can get offsets. - std::string b; - auto c = compressed - ? std::make_unique( - 0, b, pl::create(pl::create(hint_buffer), Pl_Flate::a_deflate)) - : std::make_unique(0, hint_buffer); - - BitWriter w(c.get()); + pl::Count c(0, hint_buffer); + BitWriter w(&c); writeHPageOffset(w); - S = toI(c->getCount()); + S = toI(c.getCount()); writeHSharedObject(w); O = 0; if (m->outline_hints.nobjects > 0) { - O = toI(c->getCount()); + O = toI(c.getCount()); writeHGeneric(w, m->outline_hints); } - c->finish(); + if (compressed) { + hint_buffer = pl::pipe(hint_buffer, Pl_Flate::a_deflate); + } } -- libgit2 0.21.4