Commit c934608de6c78a668d95cb5da076feac993f801a
1 parent
5e791513
Refactor `Pl_stack` in `QPDFWriter` to replace `next_stack_id` with `last_id`, s…
…implifying ID management and ensuring consistent initialization.
Showing
1 changed file
with
10 additions
and
13 deletions
libqpdf/QPDFWriter.cc
| ... | ... | @@ -122,7 +122,7 @@ namespace |
| 122 | 122 | void |
| 123 | 123 | initialize(Pipeline* p) |
| 124 | 124 | { |
| 125 | - auto c = std::make_unique<pl::Count>(1, p); | |
| 125 | + auto c = std::make_unique<pl::Count>(++last_id, p); | |
| 126 | 126 | top = c.get(); |
| 127 | 127 | stack.emplace_back(std::move(c)); |
| 128 | 128 | } |
| ... | ... | @@ -168,18 +168,17 @@ namespace |
| 168 | 168 | { |
| 169 | 169 | std::unique_ptr<pl::Count> c; |
| 170 | 170 | if (link) { |
| 171 | - c = std::make_unique<pl::Count>(next_stack_id, count_buffer, std::move(link)); | |
| 171 | + c = std::make_unique<pl::Count>(++last_id, count_buffer, std::move(link)); | |
| 172 | 172 | } else if (discard) { |
| 173 | - c = std::make_unique<pl::Count>(next_stack_id, nullptr); | |
| 173 | + c = std::make_unique<pl::Count>(++last_id, nullptr); | |
| 174 | 174 | } else if (!str) { |
| 175 | - c = std::make_unique<pl::Count>(next_stack_id, top); | |
| 175 | + c = std::make_unique<pl::Count>(++last_id, top); | |
| 176 | 176 | } else { |
| 177 | - c = std::make_unique<pl::Count>(next_stack_id, *str); | |
| 177 | + c = std::make_unique<pl::Count>(++last_id, *str); | |
| 178 | 178 | } |
| 179 | - pp.stack_id = next_stack_id; | |
| 179 | + pp.stack_id = last_id; | |
| 180 | 180 | top = c.get(); |
| 181 | 181 | stack.emplace_back(std::move(c)); |
| 182 | - ++next_stack_id; | |
| 183 | 182 | } |
| 184 | 183 | void |
| 185 | 184 | activate_md5(Popper& pp) |
| ... | ... | @@ -190,12 +189,11 @@ namespace |
| 190 | 189 | md5_pipeline = std::make_unique<Pl_MD5>("qpdf md5", top); |
| 191 | 190 | md5_pipeline->persistAcrossFinish(true); |
| 192 | 191 | // Special case code in pop clears m->md5_pipeline upon deletion. |
| 193 | - auto c = std::make_unique<pl::Count>(next_stack_id, md5_pipeline.get()); | |
| 194 | - pp.stack_id = next_stack_id; | |
| 195 | - md5_id = next_stack_id; | |
| 192 | + auto c = std::make_unique<pl::Count>(++last_id, md5_pipeline.get()); | |
| 193 | + pp.stack_id = last_id; | |
| 194 | + md5_id = last_id; | |
| 196 | 195 | top = c.get(); |
| 197 | 196 | stack.emplace_back(std::move(c)); |
| 198 | - ++next_stack_id; | |
| 199 | 197 | } |
| 200 | 198 | |
| 201 | 199 | void |
| ... | ... | @@ -230,11 +228,10 @@ namespace |
| 230 | 228 | std::vector<std::unique_ptr<pl::Count>> stack; |
| 231 | 229 | pl::Count*& top; |
| 232 | 230 | std::unique_ptr<Pl_MD5>& md5_pipeline; |
| 233 | - unsigned long next_stack_id{2}; | |
| 231 | + unsigned long last_id{0}; | |
| 234 | 232 | unsigned long md5_id{0}; |
| 235 | 233 | std::string count_buffer; |
| 236 | 234 | }; |
| 237 | - | |
| 238 | 235 | } // namespace |
| 239 | 236 | |
| 240 | 237 | Pl_stack::Popper::~Popper() | ... | ... |