From 7b3427502a6b469120f8eee0cf6dc5f9c3315c23 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 19 Jul 2025 18:32:35 +0100 Subject: [PATCH] Refactor `QPDFWriter` to replace `pl::Link` with direct use of `Pipeline` for improved clarity and reduced indirection in pipeline management. --- libqpdf/QPDFWriter.cc | 10 ++++------ libqpdf/qpdf/Pipeline_private.hh | 39 +++++---------------------------------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 26b18ec..ba52fd9 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -141,7 +141,7 @@ namespace } void - activate(Popper& pp, std::unique_ptr link) + activate(Popper& pp, std::unique_ptr link) { count_buffer.clear(); activate(pp, false, &count_buffer, std::move(link)); @@ -151,7 +151,7 @@ namespace activate( bool discard = false, std::string* str = nullptr, - std::unique_ptr link = nullptr) + std::unique_ptr link = nullptr) { Popper pp{*this}; activate(pp, discard, str, std::move(link)); @@ -163,7 +163,7 @@ namespace Popper& pp, bool discard = false, std::string* str = nullptr, - std::unique_ptr link = nullptr) + std::unique_ptr link = nullptr) { std::unique_ptr c; if (link) { @@ -2735,9 +2735,7 @@ QPDFWriter::writeLinearized() lin_pass1_file = QUtil::safe_fopen(m->lin_pass1_filename.c_str(), "wb"); m->pipeline_stack.activate( pp_pass1, - std::make_unique( - nullptr, - std::make_unique("linearization pass1", lin_pass1_file))); + std::make_unique("linearization pass1", lin_pass1_file)); } else { m->pipeline_stack.activate(pp_pass1, true); } diff --git a/libqpdf/qpdf/Pipeline_private.hh b/libqpdf/qpdf/Pipeline_private.hh index 2bc5872..c19dd41 100644 --- a/libqpdf/qpdf/Pipeline_private.hh +++ b/libqpdf/qpdf/Pipeline_private.hh @@ -8,35 +8,6 @@ namespace qpdf::pl { - struct Link - { - Link(std::unique_ptr next_link, std::unique_ptr next_pl) : - next_link(std::move(next_link)), - next_pl(std::move(next_pl)) - { - } - - std::unique_ptr next_link{nullptr}; - std::unique_ptr next_pl{nullptr}; - }; - - template - std::unique_ptr - create(Args&&... args) - { - return std::make_unique( - nullptr, std::make_unique

("", nullptr, std::forward(args)...)); - } - - template - std::unique_ptr - create(std::unique_ptr link, Args&&... args) - { - auto* next = link->next_pl.get(); - return std::make_unique( - std::move(link), std::make_unique

("", next, std::forward(args)...)); - } - class String final: public Pipeline { public: @@ -85,8 +56,8 @@ namespace qpdf::pl // Count the number of characters written. If 'next' is not set, the content written will be // discarded. - Count(unsigned long id, std::unique_ptr link) : - Pipeline("", link ? link->next_pl.get() : nullptr), + Count(unsigned long id, std::unique_ptr link) : + Pipeline("", link ? link.get() : nullptr), link(std::move(link)), id_(id), pass_immediately_to_next(link) @@ -95,8 +66,8 @@ namespace qpdf::pl // Write to 'str'. If 'next' is set, 'str' will be written to 'next' when 'finish' is // called. - Count(unsigned long id, std::string& str, std::unique_ptr link = nullptr) : - Pipeline("", link ? link->next_pl.get() : nullptr), + Count(unsigned long id, std::string& str, std::unique_ptr link = nullptr) : + Pipeline("", link ? link.get() : nullptr), str(&str), link(std::move(link)), id_(id) @@ -169,7 +140,7 @@ namespace qpdf::pl private: qpdf_offset_t count{0}; std::string* str{nullptr}; - std::unique_ptr link{nullptr}; + std::unique_ptr link{nullptr}; unsigned long id_{0}; bool pass_immediately_to_next{false}; }; -- libgit2 0.21.4