From cbd5db35abcaecc222c93339b3fb4da0076ee402 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 2 Nov 2025 10:44:42 +0000 Subject: [PATCH] Refactor `QPDFEFStreamObjectHelper`: simplify dictionary access, replace redundant checks, and streamline string handling. --- libqpdf/QPDFEFStreamObjectHelper.cc | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/libqpdf/QPDFEFStreamObjectHelper.cc b/libqpdf/QPDFEFStreamObjectHelper.cc index 0992fa0..e6d82b9 100644 --- a/libqpdf/QPDFEFStreamObjectHelper.cc +++ b/libqpdf/QPDFEFStreamObjectHelper.cc @@ -5,8 +5,11 @@ #include #include #include +#include #include +using namespace qpdf; + class QPDFEFStreamObjectHelper::Members { }; @@ -19,41 +22,38 @@ QPDFEFStreamObjectHelper::QPDFEFStreamObjectHelper(QPDFObjectHandle oh) : QPDFObjectHandle QPDFEFStreamObjectHelper::getParam(std::string const& pkey) { - auto params = oh().getDict().getKey("/Params"); - if (params.isDictionary()) { - return params.getKey(pkey); + if (auto result = oh().getDict()["/Params"][pkey]) { + return result; } - return QPDFObjectHandle::newNull(); + return {}; } void QPDFEFStreamObjectHelper::setParam(std::string const& pkey, QPDFObjectHandle const& pval) { - auto params = oh().getDict().getKey("/Params"); - if (!params.isDictionary()) { - params = oh().getDict().replaceKeyAndGetNew("/Params", QPDFObjectHandle::newDictionary()); + if (Dictionary Params = oh().getDict()["/Params"]) { + Params.replaceKey(pkey, pval); + return; } - params.replaceKey(pkey, pval); + oh().getDict().replaceKey("/Params", Dictionary({{pkey, pval}})); } std::string QPDFEFStreamObjectHelper::getCreationDate() { - auto val = getParam("/CreationDate"); - if (val.isString()) { - return val.getUTF8Value(); + if (String CreationDate = getParam("/CreationDate")) { + return CreationDate.utf8_value(); } - return ""; + return {}; } std::string QPDFEFStreamObjectHelper::getModDate() { - auto val = getParam("/ModDate"); - if (val.isString()) { - return val.getUTF8Value(); + if (String ModDate = getParam("/ModDate")) { + return ModDate.utf8_value(); } - return ""; + return {}; } size_t @@ -82,11 +82,10 @@ QPDFEFStreamObjectHelper::getSubtype() std::string QPDFEFStreamObjectHelper::getChecksum() { - auto val = getParam("/CheckSum"); - if (val.isString()) { - return val.getStringValue(); + if (String CheckSum = getParam("/CheckSum")) { + return CheckSum.value(); } - return ""; + return {}; } QPDFEFStreamObjectHelper -- libgit2 0.21.4