Commit 5c1a5d433f1566dc1a75c261c372d87204810932
1 parent
5806e305
I SF_FlateLzwDecode switch from shared_ptr to unique_ptr for pipeline management
Replaced `std::shared_ptr` with `std::unique_ptr` in `SF_FlateLzwDecode` to improve memory management and clarify ownership semantics. Adjusted related code and function logic to accommodate the change, including moving pipelines into the vector.
Showing
2 changed files
with
21 additions
and
24 deletions
libqpdf/SF_FlateLzwDecode.cc
| @@ -69,48 +69,37 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms) | @@ -69,48 +69,37 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms) | ||
| 69 | Pipeline* | 69 | Pipeline* |
| 70 | SF_FlateLzwDecode::getDecodePipeline(Pipeline* next) | 70 | SF_FlateLzwDecode::getDecodePipeline(Pipeline* next) |
| 71 | { | 71 | { |
| 72 | - std::shared_ptr<Pipeline> pipeline; | 72 | + std::unique_ptr<Pipeline> pipeline; |
| 73 | if (predictor >= 10 && predictor <= 15) { | 73 | if (predictor >= 10 && predictor <= 15) { |
| 74 | QTC::TC("qpdf", "SF_FlateLzwDecode PNG filter"); | 74 | QTC::TC("qpdf", "SF_FlateLzwDecode PNG filter"); |
| 75 | - pipeline = std::make_shared<Pl_PNGFilter>( | 75 | + pipeline = std::make_unique<Pl_PNGFilter>( |
| 76 | "png decode", | 76 | "png decode", |
| 77 | next, | 77 | next, |
| 78 | Pl_PNGFilter::a_decode, | 78 | Pl_PNGFilter::a_decode, |
| 79 | QIntC::to_uint(columns), | 79 | QIntC::to_uint(columns), |
| 80 | QIntC::to_uint(colors), | 80 | QIntC::to_uint(colors), |
| 81 | QIntC::to_uint(bits_per_component)); | 81 | QIntC::to_uint(bits_per_component)); |
| 82 | - pipelines.push_back(pipeline); | ||
| 83 | next = pipeline.get(); | 82 | next = pipeline.get(); |
| 83 | + pipelines.push_back(std::move(pipeline)); | ||
| 84 | } else if (predictor == 2) { | 84 | } else if (predictor == 2) { |
| 85 | QTC::TC("qpdf", "SF_FlateLzwDecode TIFF predictor"); | 85 | QTC::TC("qpdf", "SF_FlateLzwDecode TIFF predictor"); |
| 86 | - pipeline = std::make_shared<Pl_TIFFPredictor>( | 86 | + pipeline = std::make_unique<Pl_TIFFPredictor>( |
| 87 | "tiff decode", | 87 | "tiff decode", |
| 88 | next, | 88 | next, |
| 89 | Pl_TIFFPredictor::a_decode, | 89 | Pl_TIFFPredictor::a_decode, |
| 90 | QIntC::to_uint(columns), | 90 | QIntC::to_uint(columns), |
| 91 | QIntC::to_uint(colors), | 91 | QIntC::to_uint(colors), |
| 92 | QIntC::to_uint(bits_per_component)); | 92 | QIntC::to_uint(bits_per_component)); |
| 93 | - pipelines.push_back(pipeline); | ||
| 94 | next = pipeline.get(); | 93 | next = pipeline.get(); |
| 94 | + pipelines.push_back(std::move(pipeline)); | ||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | if (lzw) { | 97 | if (lzw) { |
| 98 | - pipeline = std::make_shared<Pl_LZWDecoder>("lzw decode", next, early_code_change); | 98 | + pipeline = std::make_unique<Pl_LZWDecoder>("lzw decode", next, early_code_change); |
| 99 | } else { | 99 | } else { |
| 100 | - pipeline = std::make_shared<Pl_Flate>("stream inflate", next, Pl_Flate::a_inflate); | 100 | + pipeline = std::make_unique<Pl_Flate>("stream inflate", next, Pl_Flate::a_inflate); |
| 101 | } | 101 | } |
| 102 | - pipelines.push_back(pipeline); | ||
| 103 | - return pipeline.get(); | ||
| 104 | -} | ||
| 105 | - | ||
| 106 | -std::shared_ptr<QPDFStreamFilter> | ||
| 107 | -SF_FlateLzwDecode::flate_factory() | ||
| 108 | -{ | ||
| 109 | - return std::make_shared<SF_FlateLzwDecode>(false); | ||
| 110 | -} | ||
| 111 | - | ||
| 112 | -std::shared_ptr<QPDFStreamFilter> | ||
| 113 | -SF_FlateLzwDecode::lzw_factory() | ||
| 114 | -{ | ||
| 115 | - return std::make_shared<SF_FlateLzwDecode>(true); | 102 | + next = pipeline.get(); |
| 103 | + pipelines.push_back(std::move(pipeline)); | ||
| 104 | + return next; | ||
| 116 | } | 105 | } |
libqpdf/qpdf/SF_FlateLzwDecode.hh
| @@ -17,8 +17,16 @@ class SF_FlateLzwDecode final: public QPDFStreamFilter | @@ -17,8 +17,16 @@ class SF_FlateLzwDecode final: public QPDFStreamFilter | ||
| 17 | bool setDecodeParms(QPDFObjectHandle decode_parms) final; | 17 | bool setDecodeParms(QPDFObjectHandle decode_parms) final; |
| 18 | Pipeline* getDecodePipeline(Pipeline* next) final; | 18 | Pipeline* getDecodePipeline(Pipeline* next) final; |
| 19 | 19 | ||
| 20 | - static std::shared_ptr<QPDFStreamFilter> flate_factory(); | ||
| 21 | - static std::shared_ptr<QPDFStreamFilter> lzw_factory(); | 20 | + static std::shared_ptr<QPDFStreamFilter> |
| 21 | + flate_factory() | ||
| 22 | + { | ||
| 23 | + return std::make_shared<SF_FlateLzwDecode>(false); | ||
| 24 | + } | ||
| 25 | + static std::shared_ptr<QPDFStreamFilter> | ||
| 26 | + lzw_factory() | ||
| 27 | + { | ||
| 28 | + return std::make_shared<SF_FlateLzwDecode>(true); | ||
| 29 | + } | ||
| 22 | 30 | ||
| 23 | private: | 31 | private: |
| 24 | bool lzw{}; | 32 | bool lzw{}; |
| @@ -28,7 +36,7 @@ class SF_FlateLzwDecode final: public QPDFStreamFilter | @@ -28,7 +36,7 @@ class SF_FlateLzwDecode final: public QPDFStreamFilter | ||
| 28 | int colors{1}; | 36 | int colors{1}; |
| 29 | int bits_per_component{8}; | 37 | int bits_per_component{8}; |
| 30 | bool early_code_change{true}; | 38 | bool early_code_change{true}; |
| 31 | - std::vector<std::shared_ptr<Pipeline>> pipelines; | 39 | + std::vector<std::unique_ptr<Pipeline>> pipelines; |
| 32 | }; | 40 | }; |
| 33 | 41 | ||
| 34 | #endif // SF_FLATELZWDECODE_HH | 42 | #endif // SF_FLATELZWDECODE_HH |