From e6200bbcc516aa34d74cd92be56eb88c918629fa Mon Sep 17 00:00:00 2001 From: m-holger Date: Sat, 30 Aug 2025 12:22:44 +0100 Subject: [PATCH] Refactor `QPDFAcroFormDocumentHelper::Members` to use `std::make_shared`, improve memory management, and streamline class definition. --- include/qpdf/QPDFAcroFormDocumentHelper.hh | 18 +----------------- libqpdf/QPDFAcroFormDocumentHelper.cc | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/include/qpdf/QPDFAcroFormDocumentHelper.hh b/include/qpdf/QPDFAcroFormDocumentHelper.hh index 6094ed7..0ac2313 100644 --- a/include/qpdf/QPDFAcroFormDocumentHelper.hh +++ b/include/qpdf/QPDFAcroFormDocumentHelper.hh @@ -241,23 +241,7 @@ class QPDFAcroFormDocumentHelper: public QPDFDocumentHelper void adjustAppearanceStream( QPDFObjectHandle stream, std::map> dr_map); - class Members - { - friend class QPDFAcroFormDocumentHelper; - - public: - ~Members() = default; - - private: - Members() = default; - Members(Members const&) = delete; - - bool cache_valid{false}; - std::map> field_to_annotations; - std::map annotation_to_field; - std::map field_to_name; - std::map> name_to_fields; - }; + class Members; std::shared_ptr m; }; diff --git a/libqpdf/QPDFAcroFormDocumentHelper.cc b/libqpdf/QPDFAcroFormDocumentHelper.cc index 6974133..e3a0c95 100644 --- a/libqpdf/QPDFAcroFormDocumentHelper.cc +++ b/libqpdf/QPDFAcroFormDocumentHelper.cc @@ -13,9 +13,23 @@ using namespace qpdf; using namespace std::literals; +class QPDFAcroFormDocumentHelper::Members +{ + public: + Members() = default; + Members(Members const&) = delete; + ~Members() = default; + + bool cache_valid{false}; + std::map> field_to_annotations; + std::map annotation_to_field; + std::map field_to_name; + std::map> name_to_fields; +}; + QPDFAcroFormDocumentHelper::QPDFAcroFormDocumentHelper(QPDF& qpdf) : QPDFDocumentHelper(qpdf), - m(new Members()) + m(std::make_shared()) { // We have to analyze up front. Otherwise, when we are adding annotations and fields, we are in // a temporarily unstable configuration where some widget annotations are not reachable. -- libgit2 0.21.4