Commit 9cdf980f3b096dd8360d4286ebcd1f29ebb8d35b

Authored by m-holger
1 parent a03c5fce

Refactor decode object handling in QPDF_Stream.cc

Simplified the logic for handling /DecodeParms by using `as_array` and modernized code with `auto` and `emplace_back`. This improves code readability and aligns with modern C++ practices.
Showing 1 changed file with 10 additions and 10 deletions
libqpdf/QPDF_Stream.cc
... ... @@ -383,21 +383,21 @@ Stream::filterable(
383 383 }
384 384  
385 385 // filters now contains a list of filters to be applied in order. See which ones we can support.
386   -
387 386 // See if we can support any decode parameters that are specified.
388 387  
389   - QPDFObjectHandle decode_obj = s->stream_dict.getKey("/DecodeParms");
  388 + auto decode_obj = s->stream_dict.getKey("/DecodeParms");
390 389 std::vector<QPDFObjectHandle> decode_parms;
391   - if (decode_obj.isArray() && (decode_obj.getArrayNItems() == 0)) {
392   - decode_obj = QPDFObjectHandle::newNull();
393   - }
394   - if (decode_obj.isArray()) {
395   - for (int i = 0; i < decode_obj.getArrayNItems(); ++i) {
396   - decode_parms.push_back(decode_obj.getArrayItem(i));
  390 +
  391 + auto decode_array = decode_obj.as_array(strict);
  392 + if (!decode_array || decode_array.size() == 0) {
  393 + if (decode_array) {
  394 + decode_parms.assign(filters.size(), QPDFObjectHandle::newNull());
  395 + } else {
  396 + decode_parms.assign(filters.size(), decode_obj);
397 397 }
398 398 } else {
399   - for (unsigned int i = 0; i < filters.size(); ++i) {
400   - decode_parms.push_back(decode_obj);
  399 + for (auto& item: decode_array) {
  400 + decode_parms.emplace_back(item);
401 401 }
402 402 }
403 403  
... ...