Commit 4925f0d18c5554bf96d8cb853b5a017e0d18fda2

Authored by Jay Berkenbilt
1 parent 68e72198

Have dictionary/streams mutators take const& where possible

include/qpdf/QPDFObjectHandle.hh
@@ -1025,13 +1025,13 @@ class QPDFObjectHandle @@ -1025,13 +1025,13 @@ class QPDFObjectHandle
1025 1025
1026 // Replace value of key, adding it if it does not exist 1026 // Replace value of key, adding it if it does not exist
1027 QPDF_DLL 1027 QPDF_DLL
1028 - void replaceKey(std::string const& key, QPDFObjectHandle); 1028 + void replaceKey(std::string const& key, QPDFObjectHandle const&);
1029 // Remove key, doing nothing if key does not exist 1029 // Remove key, doing nothing if key does not exist
1030 QPDF_DLL 1030 QPDF_DLL
1031 void removeKey(std::string const& key); 1031 void removeKey(std::string const& key);
1032 // If the object is null, remove the key. Otherwise, replace it. 1032 // If the object is null, remove the key. Otherwise, replace it.
1033 QPDF_DLL 1033 QPDF_DLL
1034 - void replaceOrRemoveKey(std::string const& key, QPDFObjectHandle); 1034 + void replaceOrRemoveKey(std::string const& key, QPDFObjectHandle const&);
1035 1035
1036 // Methods for stream objects 1036 // Methods for stream objects
1037 QPDF_DLL 1037 QPDF_DLL
@@ -1164,7 +1164,7 @@ class QPDFObjectHandle @@ -1164,7 +1164,7 @@ class QPDFObjectHandle
1164 // may be more convenient in this case than calling getDict and 1164 // may be more convenient in this case than calling getDict and
1165 // modifying it for each key. The pdf-create example does this. 1165 // modifying it for each key. The pdf-create example does this.
1166 QPDF_DLL 1166 QPDF_DLL
1167 - void replaceDict(QPDFObjectHandle); 1167 + void replaceDict(QPDFObjectHandle const&);
1168 1168
1169 // Replace this stream's stream data with the given data buffer, 1169 // Replace this stream's stream data with the given data buffer,
1170 // and replace the /Filter and /DecodeParms keys in the stream 1170 // and replace the /Filter and /DecodeParms keys in the stream
libqpdf/QPDFObjectHandle.cc
@@ -1268,7 +1268,8 @@ QPDFObjectHandle::getOwningQPDF() @@ -1268,7 +1268,8 @@ QPDFObjectHandle::getOwningQPDF()
1268 // Dictionary mutators 1268 // Dictionary mutators
1269 1269
1270 void 1270 void
1271 -QPDFObjectHandle::replaceKey(std::string const& key, QPDFObjectHandle value) 1271 +QPDFObjectHandle::replaceKey(
  1272 + std::string const& key, QPDFObjectHandle const& value)
1272 { 1273 {
1273 if (isDictionary()) { 1274 if (isDictionary()) {
1274 checkOwnership(value); 1275 checkOwnership(value);
@@ -1292,7 +1293,7 @@ QPDFObjectHandle::removeKey(std::string const& key) @@ -1292,7 +1293,7 @@ QPDFObjectHandle::removeKey(std::string const& key)
1292 1293
1293 void 1294 void
1294 QPDFObjectHandle::replaceOrRemoveKey( 1295 QPDFObjectHandle::replaceOrRemoveKey(
1295 - std::string const& key, QPDFObjectHandle value) 1296 + std::string const& key, QPDFObjectHandle const& value)
1296 { 1297 {
1297 if (isDictionary()) { 1298 if (isDictionary()) {
1298 checkOwnership(value); 1299 checkOwnership(value);
@@ -1334,7 +1335,7 @@ QPDFObjectHandle::isDataModified() @@ -1334,7 +1335,7 @@ QPDFObjectHandle::isDataModified()
1334 } 1335 }
1335 1336
1336 void 1337 void
1337 -QPDFObjectHandle::replaceDict(QPDFObjectHandle new_dict) 1338 +QPDFObjectHandle::replaceDict(QPDFObjectHandle const& new_dict)
1338 { 1339 {
1339 assertStream(); 1340 assertStream();
1340 dynamic_cast<QPDF_Stream*>(obj.get())->replaceDict(new_dict); 1341 dynamic_cast<QPDF_Stream*>(obj.get())->replaceDict(new_dict);
libqpdf/QPDF_Dictionary.cc
@@ -115,7 +115,8 @@ QPDF_Dictionary::getAsMap() const @@ -115,7 +115,8 @@ QPDF_Dictionary::getAsMap() const
115 } 115 }
116 116
117 void 117 void
118 -QPDF_Dictionary::replaceKey(std::string const& key, QPDFObjectHandle value) 118 +QPDF_Dictionary::replaceKey(
  119 + std::string const& key, QPDFObjectHandle const& value)
119 { 120 {
120 // add or replace value 121 // add or replace value
121 this->items[key] = value; 122 this->items[key] = value;
libqpdf/QPDF_Stream.cc
@@ -617,11 +617,11 @@ QPDF_Stream::replaceFilterData( @@ -617,11 +617,11 @@ QPDF_Stream::replaceFilterData(
617 } 617 }
618 618
619 void 619 void
620 -QPDF_Stream::replaceDict(QPDFObjectHandle new_dict) 620 +QPDF_Stream::replaceDict(QPDFObjectHandle const& new_dict)
621 { 621 {
622 this->stream_dict = new_dict; 622 this->stream_dict = new_dict;
623 setDictDescription(); 623 setDictDescription();
624 - QPDFObjectHandle length_obj = new_dict.getKey("/Length"); 624 + QPDFObjectHandle length_obj = this->stream_dict.getKey("/Length");
625 if (length_obj.isInteger()) { 625 if (length_obj.isInteger()) {
626 this->length = QIntC::to_size(length_obj.getUIntValue()); 626 this->length = QIntC::to_size(length_obj.getUIntValue());
627 } else { 627 } else {
libqpdf/qpdf/QPDF_Dictionary.hh
@@ -28,7 +28,7 @@ class QPDF_Dictionary: public QPDFObject @@ -28,7 +28,7 @@ class QPDF_Dictionary: public QPDFObject
28 std::map<std::string, QPDFObjectHandle> const& getAsMap() const; 28 std::map<std::string, QPDFObjectHandle> const& getAsMap() const;
29 29
30 // Replace value of key, adding it if it does not exist 30 // Replace value of key, adding it if it does not exist
31 - void replaceKey(std::string const& key, QPDFObjectHandle); 31 + void replaceKey(std::string const& key, QPDFObjectHandle const&);
32 // Remove key, doing nothing if key does not exist 32 // Remove key, doing nothing if key does not exist
33 void removeKey(std::string const& key); 33 void removeKey(std::string const& key);
34 // If object is null, remove key; otherwise, replace key 34 // If object is null, remove key; otherwise, replace key
libqpdf/qpdf/QPDF_Stream.hh
@@ -62,7 +62,7 @@ class QPDF_Stream: public QPDFObject @@ -62,7 +62,7 @@ class QPDF_Stream: public QPDFObject
62 void 62 void
63 addTokenFilter(std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter); 63 addTokenFilter(std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter);
64 64
65 - void replaceDict(QPDFObjectHandle new_dict); 65 + void replaceDict(QPDFObjectHandle const& new_dict);
66 66
67 static void registerStreamFilter( 67 static void registerStreamFilter(
68 std::string const& filter_name, 68 std::string const& filter_name,