From 4925f0d18c5554bf96d8cb853b5a017e0d18fda2 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 24 Apr 2022 09:05:50 -0400 Subject: Have dictionary/streams mutators take const& where possible --- libqpdf/QPDFObjectHandle.cc | 7 ++++--- libqpdf/QPDF_Dictionary.cc | 3 ++- libqpdf/QPDF_Stream.cc | 4 ++-- libqpdf/qpdf/QPDF_Dictionary.hh | 2 +- libqpdf/qpdf/QPDF_Stream.hh | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 9fadbef3..516e38b9 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -1268,7 +1268,8 @@ QPDFObjectHandle::getOwningQPDF() // Dictionary mutators void -QPDFObjectHandle::replaceKey(std::string const& key, QPDFObjectHandle value) +QPDFObjectHandle::replaceKey( + std::string const& key, QPDFObjectHandle const& value) { if (isDictionary()) { checkOwnership(value); @@ -1292,7 +1293,7 @@ QPDFObjectHandle::removeKey(std::string const& key) void QPDFObjectHandle::replaceOrRemoveKey( - std::string const& key, QPDFObjectHandle value) + std::string const& key, QPDFObjectHandle const& value) { if (isDictionary()) { checkOwnership(value); @@ -1334,7 +1335,7 @@ QPDFObjectHandle::isDataModified() } void -QPDFObjectHandle::replaceDict(QPDFObjectHandle new_dict) +QPDFObjectHandle::replaceDict(QPDFObjectHandle const& new_dict) { assertStream(); dynamic_cast(obj.get())->replaceDict(new_dict); diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc index 599f7224..1655f53a 100644 --- a/libqpdf/QPDF_Dictionary.cc +++ b/libqpdf/QPDF_Dictionary.cc @@ -115,7 +115,8 @@ QPDF_Dictionary::getAsMap() const } void -QPDF_Dictionary::replaceKey(std::string const& key, QPDFObjectHandle value) +QPDF_Dictionary::replaceKey( + std::string const& key, QPDFObjectHandle const& value) { // add or replace value this->items[key] = value; diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc index c36b7725..cbc65611 100644 --- a/libqpdf/QPDF_Stream.cc +++ b/libqpdf/QPDF_Stream.cc @@ -617,11 +617,11 @@ QPDF_Stream::replaceFilterData( } void -QPDF_Stream::replaceDict(QPDFObjectHandle new_dict) +QPDF_Stream::replaceDict(QPDFObjectHandle const& new_dict) { this->stream_dict = new_dict; setDictDescription(); - QPDFObjectHandle length_obj = new_dict.getKey("/Length"); + QPDFObjectHandle length_obj = this->stream_dict.getKey("/Length"); if (length_obj.isInteger()) { this->length = QIntC::to_size(length_obj.getUIntValue()); } else { diff --git a/libqpdf/qpdf/QPDF_Dictionary.hh b/libqpdf/qpdf/QPDF_Dictionary.hh index 8626d59b..42ee6cf9 100644 --- a/libqpdf/qpdf/QPDF_Dictionary.hh +++ b/libqpdf/qpdf/QPDF_Dictionary.hh @@ -28,7 +28,7 @@ class QPDF_Dictionary: public QPDFObject std::map const& getAsMap() const; // Replace value of key, adding it if it does not exist - void replaceKey(std::string const& key, QPDFObjectHandle); + void replaceKey(std::string const& key, QPDFObjectHandle const&); // Remove key, doing nothing if key does not exist void removeKey(std::string const& key); // If object is null, remove key; otherwise, replace key diff --git a/libqpdf/qpdf/QPDF_Stream.hh b/libqpdf/qpdf/QPDF_Stream.hh index a6ee9551..ba456e76 100644 --- a/libqpdf/qpdf/QPDF_Stream.hh +++ b/libqpdf/qpdf/QPDF_Stream.hh @@ -62,7 +62,7 @@ class QPDF_Stream: public QPDFObject void addTokenFilter(std::shared_ptr token_filter); - void replaceDict(QPDFObjectHandle new_dict); + void replaceDict(QPDFObjectHandle const& new_dict); static void registerStreamFilter( std::string const& filter_name, -- cgit v1.2.3-70-g09d2