Commit 61a676cc2e59575eefc7e2e5c1cdbfccb8cfdef4
1 parent
f3a1139f
Refactor `NNTreeImpl`: use const references for function parameters and remove r…
…edundant debug traces.
Showing
3 changed files
with
7 additions
and
17 deletions
libqpdf/NNTree.cc
| ... | ... | @@ -866,15 +866,14 @@ NNTreeImpl::findInternal(QPDFObjectHandle const& key, bool return_prev_if_not_fo |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | NNTreeImpl::iterator |
| 869 | -NNTreeImpl::insertFirst(QPDFObjectHandle key, QPDFObjectHandle value) | |
| 869 | +NNTreeImpl::insertFirst(QPDFObjectHandle const& key, QPDFObjectHandle const& value) | |
| 870 | 870 | { |
| 871 | 871 | auto iter = begin(); |
| 872 | 872 | QPDFObjectHandle items; |
| 873 | 873 | if (iter.node.isDictionary()) { |
| 874 | 874 | items = iter.node.getKey(details.itemsKey()); |
| 875 | 875 | } |
| 876 | - if (!(items.isArray())) { | |
| 877 | - QTC::TC("qpdf", "NNTree no valid items node in insertFirst"); | |
| 876 | + if (!items.isArray()) { | |
| 878 | 877 | error(oh, "unable to find a valid items node"); |
| 879 | 878 | } |
| 880 | 879 | items.insertItem(0, key); |
| ... | ... | @@ -886,30 +885,26 @@ NNTreeImpl::insertFirst(QPDFObjectHandle key, QPDFObjectHandle value) |
| 886 | 885 | } |
| 887 | 886 | |
| 888 | 887 | NNTreeImpl::iterator |
| 889 | -NNTreeImpl::insert(QPDFObjectHandle key, QPDFObjectHandle value) | |
| 888 | +NNTreeImpl::insert(QPDFObjectHandle const& key, QPDFObjectHandle const& value) | |
| 890 | 889 | { |
| 891 | 890 | auto iter = find(key, true); |
| 892 | 891 | if (!iter.valid()) { |
| 893 | - QTC::TC("qpdf", "NNTree insert inserts first"); | |
| 894 | 892 | return insertFirst(key, value); |
| 895 | 893 | } else if (details.compareKeys(key, iter->first) == 0) { |
| 896 | - QTC::TC("qpdf", "NNTree insert replaces"); | |
| 897 | 894 | auto items = iter.node.getKey(details.itemsKey()); |
| 898 | 895 | items.setArrayItem(iter.item_number + 1, value); |
| 899 | 896 | iter.updateIValue(); |
| 900 | 897 | } else { |
| 901 | - QTC::TC("qpdf", "NNTree insert inserts after"); | |
| 902 | 898 | iter.insertAfter(key, value); |
| 903 | 899 | } |
| 904 | 900 | return iter; |
| 905 | 901 | } |
| 906 | 902 | |
| 907 | 903 | bool |
| 908 | -NNTreeImpl::remove(QPDFObjectHandle key, QPDFObjectHandle* value) | |
| 904 | +NNTreeImpl::remove(QPDFObjectHandle const& key, QPDFObjectHandle* value) | |
| 909 | 905 | { |
| 910 | 906 | auto iter = find(key, false); |
| 911 | 907 | if (!iter.valid()) { |
| 912 | - QTC::TC("qpdf", "NNTree remove not found"); | |
| 913 | 908 | return false; |
| 914 | 909 | } |
| 915 | 910 | if (value) { | ... | ... |
libqpdf/qpdf/NNTree.hh
| ... | ... | @@ -100,9 +100,9 @@ class NNTreeImpl |
| 100 | 100 | iterator end(); |
| 101 | 101 | iterator last(); |
| 102 | 102 | iterator find(QPDFObjectHandle key, bool return_prev_if_not_found = false); |
| 103 | - iterator insertFirst(QPDFObjectHandle key, QPDFObjectHandle value); | |
| 104 | - iterator insert(QPDFObjectHandle key, QPDFObjectHandle value); | |
| 105 | - bool remove(QPDFObjectHandle key, QPDFObjectHandle* value = nullptr); | |
| 103 | + iterator insertFirst(QPDFObjectHandle const& key, QPDFObjectHandle const& value); | |
| 104 | + iterator insert(QPDFObjectHandle const& key, QPDFObjectHandle const& value); | |
| 105 | + bool remove(QPDFObjectHandle const& key, QPDFObjectHandle* value = nullptr); | |
| 106 | 106 | |
| 107 | 107 | // Change the split threshold for easier testing. There's no real reason to expose this to |
| 108 | 108 | // downstream tree helpers, but it has to be public so we can call it from the test suite. | ... | ... |
qpdf/qpdf.testcov
| ... | ... | @@ -524,11 +524,7 @@ NNTree deepen: loop 0 |
| 524 | 524 | NNTree skip invalid kid 0 |
| 525 | 525 | NNTree skip item at end of short items 0 |
| 526 | 526 | NNTree skip invalid key 0 |
| 527 | -NNTree no valid items node in insertFirst 0 | |
| 528 | 527 | NNTree deepen found empty 0 |
| 529 | -NNTree insert inserts first 0 | |
| 530 | -NNTree insert replaces 0 | |
| 531 | -NNTree insert inserts after 0 | |
| 532 | 528 | NNTree unable to determine limits 0 |
| 533 | 529 | NNTree warn indirect kid 0 |
| 534 | 530 | NNTree fix indirect kid 0 |
| ... | ... | @@ -547,7 +543,6 @@ NNTree node is not a dictionary 0 |
| 547 | 543 | NNTree limits didn't change 0 |
| 548 | 544 | NNTree increment end() 0 |
| 549 | 545 | NNTree insertAfter inserts first 0 |
| 550 | -NNTree remove not found 0 | |
| 551 | 546 | NNTree remove reset limits 0 |
| 552 | 547 | NNTree erased last item 0 |
| 553 | 548 | NNTree erased non-last item 0 | ... | ... |