Commit 154d60c4abcff6d9810c6828ac241233284c3122

Authored by m-holger
1 parent c934608d

Refactor `Pl_stack` in `QPDFWriter` to streamline MD5 pipeline activation and po…

…pping, remove redundant `PipelinePopper` usage, and improve encapsulation of MD5 handling.

# Conflicts:
#	libqpdf/QPDFWriter.cc
Showing 1 changed file with 15 additions and 10 deletions
libqpdf/QPDFWriter.cc
@@ -107,9 +107,8 @@ namespace @@ -107,9 +107,8 @@ namespace
107 }; 107 };
108 108
109 public: 109 public:
110 - Pl_stack(pl::Count*& top, std::unique_ptr<Pl_MD5>& md5_pipeline) :  
111 - top(top),  
112 - md5_pipeline(md5_pipeline) 110 + Pl_stack(pl::Count*& top) :
  111 + top(top)
113 { 112 {
114 } 113 }
115 114
@@ -196,6 +195,16 @@ namespace @@ -196,6 +195,16 @@ namespace
196 stack.emplace_back(std::move(c)); 195 stack.emplace_back(std::move(c));
197 } 196 }
198 197
  198 + // Return the hex digest and disable the MD5 pipeline.
  199 + std::string
  200 + hex_digest()
  201 + {
  202 + qpdf_assert_debug(md5_pipeline);
  203 + auto digest = md5_pipeline->getHexDigest();
  204 + md5_pipeline->enable(false);
  205 + return digest;
  206 + }
  207 +
199 void 208 void
200 clear_buffer() 209 clear_buffer()
201 { 210 {
@@ -227,7 +236,7 @@ namespace @@ -227,7 +236,7 @@ namespace
227 236
228 std::vector<std::unique_ptr<pl::Count>> stack; 237 std::vector<std::unique_ptr<pl::Count>> stack;
229 pl::Count*& top; 238 pl::Count*& top;
230 - std::unique_ptr<Pl_MD5>& md5_pipeline; 239 + std::unique_ptr<Pl_MD5> md5_pipeline{nullptr};
231 unsigned long last_id{0}; 240 unsigned long last_id{0};
232 unsigned long md5_id{0}; 241 unsigned long md5_id{0};
233 std::string count_buffer; 242 std::string count_buffer;
@@ -319,7 +328,6 @@ class QPDFWriter::Members @@ -319,7 +328,6 @@ class QPDFWriter::Members
319 std::map<int, std::vector<QPDFObjGen>> object_stream_to_objects; 328 std::map<int, std::vector<QPDFObjGen>> object_stream_to_objects;
320 Pl_stack pipeline_stack; 329 Pl_stack pipeline_stack;
321 bool deterministic_id{false}; 330 bool deterministic_id{false};
322 - std::unique_ptr<Pl_MD5> md5_pipeline{nullptr};  
323 std::string deterministic_id_data; 331 std::string deterministic_id_data;
324 bool did_write_setup{false}; 332 bool did_write_setup{false};
325 333
@@ -336,7 +344,7 @@ class QPDFWriter::Members @@ -336,7 +344,7 @@ class QPDFWriter::Members
336 QPDFWriter::Members::Members(QPDF& pdf) : 344 QPDFWriter::Members::Members(QPDF& pdf) :
337 pdf(pdf), 345 pdf(pdf),
338 root_og(pdf.getRoot().getObjGen().isIndirect() ? pdf.getRoot().getObjGen() : QPDFObjGen(-1, 0)), 346 root_og(pdf.getRoot().getObjGen().isIndirect() ? pdf.getRoot().getObjGen() : QPDFObjGen(-1, 0)),
339 - pipeline_stack(pipeline, md5_pipeline) 347 + pipeline_stack(pipeline)
340 { 348 {
341 } 349 }
342 350
@@ -1128,10 +1136,8 @@ QPDFWriter::computeDeterministicIDData() @@ -1128,10 +1136,8 @@ QPDFWriter::computeDeterministicIDData()
1128 throw std::logic_error( 1136 throw std::logic_error(
1129 "Deterministic ID computation enabled after ID generation has already occurred."); 1137 "Deterministic ID computation enabled after ID generation has already occurred.");
1130 } 1138 }
1131 - qpdf_assert_debug(m->md5_pipeline != nullptr);  
1132 qpdf_assert_debug(m->deterministic_id_data.empty()); 1139 qpdf_assert_debug(m->deterministic_id_data.empty());
1133 - m->deterministic_id_data = m->md5_pipeline->getHexDigest();  
1134 - m->md5_pipeline->enable(false); 1140 + m->deterministic_id_data = m->pipeline_stack.hex_digest();
1135 } 1141 }
1136 1142
1137 int 1143 int
@@ -2922,7 +2928,6 @@ QPDFWriter::writeLinearized() @@ -2922,7 +2928,6 @@ QPDFWriter::writeLinearized()
2922 QTC::TC("qpdf", "QPDFWriter linearized deterministic ID", need_xref_stream ? 0 : 1); 2928 QTC::TC("qpdf", "QPDFWriter linearized deterministic ID", need_xref_stream ? 0 : 1);
2923 computeDeterministicIDData(); 2929 computeDeterministicIDData();
2924 pp_md5.pop(); 2930 pp_md5.pop();
2925 - qpdf_assert_debug(m->md5_pipeline == nullptr);  
2926 } 2931 }
2927 2932
2928 // Close first pass pipeline 2933 // Close first pass pipeline