2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

Have dictionary/streams mutators take const& where possible

This commit is contained in:
Jay Berkenbilt 2022-04-24 09:05:50 -04:00
parent 68e721981a
commit 4925f0d18c
6 changed files with 13 additions and 11 deletions

View File

@ -1025,13 +1025,13 @@ class QPDFObjectHandle
// Replace value of key, adding it if it does not exist
QPDF_DLL
void replaceKey(std::string const& key, QPDFObjectHandle);
void replaceKey(std::string const& key, QPDFObjectHandle const&);
// Remove key, doing nothing if key does not exist
QPDF_DLL
void removeKey(std::string const& key);
// If the object is null, remove the key. Otherwise, replace it.
QPDF_DLL
void replaceOrRemoveKey(std::string const& key, QPDFObjectHandle);
void replaceOrRemoveKey(std::string const& key, QPDFObjectHandle const&);
// Methods for stream objects
QPDF_DLL
@ -1164,7 +1164,7 @@ class QPDFObjectHandle
// may be more convenient in this case than calling getDict and
// modifying it for each key. The pdf-create example does this.
QPDF_DLL
void replaceDict(QPDFObjectHandle);
void replaceDict(QPDFObjectHandle const&);
// Replace this stream's stream data with the given data buffer,
// and replace the /Filter and /DecodeParms keys in the stream

View File

@ -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<QPDF_Stream*>(obj.get())->replaceDict(new_dict);

View File

@ -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;

View File

@ -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 {

View File

@ -28,7 +28,7 @@ class QPDF_Dictionary: public QPDFObject
std::map<std::string, QPDFObjectHandle> 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

View File

@ -62,7 +62,7 @@ class QPDF_Stream: public QPDFObject
void
addTokenFilter(std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter);
void replaceDict(QPDFObjectHandle new_dict);
void replaceDict(QPDFObjectHandle const& new_dict);
static void registerStreamFilter(
std::string const& filter_name,