From a1a8f35b63bcad7e0cac31a205e109d6a0d70622 Mon Sep 17 00:00:00 2001 From: m-holger Date: Fri, 24 Mar 2023 15:01:40 +0000 Subject: Refactor QPDF_Array::getItem and rename to at --- libqpdf/SparseOHArray.cc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'libqpdf/SparseOHArray.cc') diff --git a/libqpdf/SparseOHArray.cc b/libqpdf/SparseOHArray.cc index 3f6376a6..c82bf145 100644 --- a/libqpdf/SparseOHArray.cc +++ b/libqpdf/SparseOHArray.cc @@ -2,6 +2,8 @@ #include +static const QPDFObjectHandle null_oh = QPDFObjectHandle::newNull(); + void SparseOHArray::append(QPDFObjectHandle oh) { @@ -23,16 +25,8 @@ SparseOHArray::append(std::shared_ptr&& obj) QPDFObjectHandle SparseOHArray::at(int idx) const { - if (idx < 0 || idx >= this->n_elements) { - throw std::logic_error( - "INTERNAL ERROR: bounds error accessing SparseOHArray element"); - } - auto const& iter = this->elements.find(idx); - if (iter == this->elements.end()) { - return QPDFObjectHandle::newNull(); - } else { - return (*iter).second; - } + auto const& iter = elements.find(idx); + return iter == elements.end() ? null_oh : (*iter).second; } void -- cgit v1.2.3-54-g00ecf