From 5c1a5d433f1566dc1a75c261c372d87204810932 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 10 May 2025 13:25:06 +0100 Subject: [PATCH] I SF_FlateLzwDecode switch from shared_ptr to unique_ptr for pipeline management --- libqpdf/SF_FlateLzwDecode.cc | 31 ++++++++++--------------------- libqpdf/qpdf/SF_FlateLzwDecode.hh | 14 +++++++++++--- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/libqpdf/SF_FlateLzwDecode.cc b/libqpdf/SF_FlateLzwDecode.cc index 433d585..bd5454d 100644 --- a/libqpdf/SF_FlateLzwDecode.cc +++ b/libqpdf/SF_FlateLzwDecode.cc @@ -69,48 +69,37 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms) Pipeline* SF_FlateLzwDecode::getDecodePipeline(Pipeline* next) { - std::shared_ptr pipeline; + std::unique_ptr pipeline; if (predictor >= 10 && predictor <= 15) { QTC::TC("qpdf", "SF_FlateLzwDecode PNG filter"); - pipeline = std::make_shared( + pipeline = std::make_unique( "png decode", next, Pl_PNGFilter::a_decode, QIntC::to_uint(columns), QIntC::to_uint(colors), QIntC::to_uint(bits_per_component)); - pipelines.push_back(pipeline); next = pipeline.get(); + pipelines.push_back(std::move(pipeline)); } else if (predictor == 2) { QTC::TC("qpdf", "SF_FlateLzwDecode TIFF predictor"); - pipeline = std::make_shared( + pipeline = std::make_unique( "tiff decode", next, Pl_TIFFPredictor::a_decode, QIntC::to_uint(columns), QIntC::to_uint(colors), QIntC::to_uint(bits_per_component)); - pipelines.push_back(pipeline); next = pipeline.get(); + pipelines.push_back(std::move(pipeline)); } if (lzw) { - pipeline = std::make_shared("lzw decode", next, early_code_change); + pipeline = std::make_unique("lzw decode", next, early_code_change); } else { - pipeline = std::make_shared("stream inflate", next, Pl_Flate::a_inflate); + pipeline = std::make_unique("stream inflate", next, Pl_Flate::a_inflate); } - pipelines.push_back(pipeline); - return pipeline.get(); -} - -std::shared_ptr -SF_FlateLzwDecode::flate_factory() -{ - return std::make_shared(false); -} - -std::shared_ptr -SF_FlateLzwDecode::lzw_factory() -{ - return std::make_shared(true); + next = pipeline.get(); + pipelines.push_back(std::move(pipeline)); + return next; } diff --git a/libqpdf/qpdf/SF_FlateLzwDecode.hh b/libqpdf/qpdf/SF_FlateLzwDecode.hh index 4b70b50..9244adc 100644 --- a/libqpdf/qpdf/SF_FlateLzwDecode.hh +++ b/libqpdf/qpdf/SF_FlateLzwDecode.hh @@ -17,8 +17,16 @@ class SF_FlateLzwDecode final: public QPDFStreamFilter bool setDecodeParms(QPDFObjectHandle decode_parms) final; Pipeline* getDecodePipeline(Pipeline* next) final; - static std::shared_ptr flate_factory(); - static std::shared_ptr lzw_factory(); + static std::shared_ptr + flate_factory() + { + return std::make_shared(false); + } + static std::shared_ptr + lzw_factory() + { + return std::make_shared(true); + } private: bool lzw{}; @@ -28,7 +36,7 @@ class SF_FlateLzwDecode final: public QPDFStreamFilter int colors{1}; int bits_per_component{8}; bool early_code_change{true}; - std::vector> pipelines; + std::vector> pipelines; }; #endif // SF_FLATELZWDECODE_HH -- libgit2 0.21.4