Commit 13d55d88cd62e416433c2402f1ba4061d67dcd28
1 parent
e78c1201
Refactor `NNTreeIterator::getNextKid`: simplify loop logic, replace `getArrayNIt…
…ems` and `getArrayItem` with `size` and subscript operators, and improve code readability.
Showing
2 changed files
with
6 additions
and
13 deletions
libqpdf/NNTree.cc
| @@ -87,28 +87,22 @@ NNTreeIterator::PathElement::PathElement(QPDFObjectHandle const& node, int kid_n | @@ -87,28 +87,22 @@ NNTreeIterator::PathElement::PathElement(QPDFObjectHandle const& node, int kid_n | ||
| 87 | QPDFObjectHandle | 87 | QPDFObjectHandle |
| 88 | NNTreeIterator::getNextKid(PathElement& pe, bool backward) | 88 | NNTreeIterator::getNextKid(PathElement& pe, bool backward) |
| 89 | { | 89 | { |
| 90 | - QPDFObjectHandle result; | ||
| 91 | - bool found = false; | ||
| 92 | - while (!found) { | 90 | + while (true) { |
| 93 | pe.kid_number += backward ? -1 : 1; | 91 | pe.kid_number += backward ? -1 : 1; |
| 94 | auto kids = pe.node.getKey("/Kids"); | 92 | auto kids = pe.node.getKey("/Kids"); |
| 95 | - if ((pe.kid_number >= 0) && (pe.kid_number < kids.getArrayNItems())) { | ||
| 96 | - result = kids.getArrayItem(pe.kid_number); | 93 | + if (pe.kid_number >= 0 && std::cmp_less(pe.kid_number, kids.size())) { |
| 94 | + auto result = kids[pe.kid_number]; | ||
| 97 | if (result.isDictionary() && | 95 | if (result.isDictionary() && |
| 98 | (result.hasKey("/Kids") || result.hasKey(impl.details.itemsKey()))) { | 96 | (result.hasKey("/Kids") || result.hasKey(impl.details.itemsKey()))) { |
| 99 | - found = true; | 97 | + return result; |
| 100 | } else { | 98 | } else { |
| 101 | - QTC::TC("qpdf", "NNTree skip invalid kid"); | ||
| 102 | impl.warn( | 99 | impl.warn( |
| 103 | - pe.node, | ||
| 104 | - ("skipping over invalid kid at index " + std::to_string(pe.kid_number))); | 100 | + pe.node, "skipping over invalid kid at index " + std::to_string(pe.kid_number)); |
| 105 | } | 101 | } |
| 106 | } else { | 102 | } else { |
| 107 | - result = QPDFObjectHandle::newNull(); | ||
| 108 | - found = true; | 103 | + return QPDFObjectHandle::newNull(); |
| 109 | } | 104 | } |
| 110 | } | 105 | } |
| 111 | - return result; | ||
| 112 | } | 106 | } |
| 113 | 107 | ||
| 114 | bool | 108 | bool |
qpdf/qpdf.testcov
| @@ -519,7 +519,6 @@ qpdf-c called qpdf_oh_unparse_resolved 0 | @@ -519,7 +519,6 @@ qpdf-c called qpdf_oh_unparse_resolved 0 | ||
| 519 | qpdf-c called qpdf_oh_unparse_binary 0 | 519 | qpdf-c called qpdf_oh_unparse_binary 0 |
| 520 | QPDFWriter getFilterOnWrite false 0 | 520 | QPDFWriter getFilterOnWrite false 0 |
| 521 | QPDFPageObjectHelper::forEachXObject 3 | 521 | QPDFPageObjectHelper::forEachXObject 3 |
| 522 | -NNTree skip invalid kid 0 | ||
| 523 | NNTree repair 0 | 522 | NNTree repair 0 |
| 524 | NNTree insertAfter inserts first 0 | 523 | NNTree insertAfter inserts first 0 |
| 525 | NNTree erased last kid/item in tree 1 | 524 | NNTree erased last kid/item in tree 1 |