Commit 5c1a5d433f1566dc1a75c261c372d87204810932

Authored by m-holger
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.
libqpdf/SF_FlateLzwDecode.cc
... ... @@ -69,48 +69,37 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms)
69 69 Pipeline*
70 70 SF_FlateLzwDecode::getDecodePipeline(Pipeline* next)
71 71 {
72   - std::shared_ptr<Pipeline> pipeline;
  72 + std::unique_ptr<Pipeline> pipeline;
73 73 if (predictor >= 10 && predictor <= 15) {
74 74 QTC::TC("qpdf", "SF_FlateLzwDecode PNG filter");
75   - pipeline = std::make_shared<Pl_PNGFilter>(
  75 + pipeline = std::make_unique<Pl_PNGFilter>(
76 76 "png decode",
77 77 next,
78 78 Pl_PNGFilter::a_decode,
79 79 QIntC::to_uint(columns),
80 80 QIntC::to_uint(colors),
81 81 QIntC::to_uint(bits_per_component));
82   - pipelines.push_back(pipeline);
83 82 next = pipeline.get();
  83 + pipelines.push_back(std::move(pipeline));
84 84 } else if (predictor == 2) {
85 85 QTC::TC("qpdf", "SF_FlateLzwDecode TIFF predictor");
86   - pipeline = std::make_shared<Pl_TIFFPredictor>(
  86 + pipeline = std::make_unique<Pl_TIFFPredictor>(
87 87 "tiff decode",
88 88 next,
89 89 Pl_TIFFPredictor::a_decode,
90 90 QIntC::to_uint(columns),
91 91 QIntC::to_uint(colors),
92 92 QIntC::to_uint(bits_per_component));
93   - pipelines.push_back(pipeline);
94 93 next = pipeline.get();
  94 + pipelines.push_back(std::move(pipeline));
95 95 }
96 96  
97 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 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 17 bool setDecodeParms(QPDFObjectHandle decode_parms) final;
18 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 31 private:
24 32 bool lzw{};
... ... @@ -28,7 +36,7 @@ class SF_FlateLzwDecode final: public QPDFStreamFilter
28 36 int colors{1};
29 37 int bits_per_component{8};
30 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 42 #endif // SF_FLATELZWDECODE_HH
... ...