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