Commit 578c5ac66c80cd1bfb43206dbba091a3985bb4bc

Authored by Jay Berkenbilt
1 parent 821a7018

Use more references when iterating

When possible, use `for (auto&` or `for (auto const&` when iterating
using C++-11 style iterators.
libqpdf/SparseOHArray.cc
@@ -57,7 +57,7 @@ SparseOHArray::remove_last() @@ -57,7 +57,7 @@ SparseOHArray::remove_last()
57 void 57 void
58 SparseOHArray::releaseResolved() 58 SparseOHArray::releaseResolved()
59 { 59 {
60 - for (auto iter: this->elements) 60 + for (auto& iter: this->elements)
61 { 61 {
62 QPDFObjectHandle::ReleaseResolver::releaseResolved(iter.second); 62 QPDFObjectHandle::ReleaseResolver::releaseResolved(iter.second);
63 } 63 }
libtests/cxx11.cc
@@ -105,7 +105,7 @@ void do_iteration() @@ -105,7 +105,7 @@ void do_iteration()
105 std::vector<int> v = { 1, 2, 3, 4 }; 105 std::vector<int> v = { 1, 2, 3, 4 };
106 assert(v.size() == 4); 106 assert(v.size() == 4);
107 int sum = 0; 107 int sum = 0;
108 - for (auto i: v) 108 + for (auto& i: v)
109 { 109 {
110 sum += i; 110 sum += i;
111 } 111 }
qpdf/fix-qdf.cc
@@ -110,7 +110,7 @@ QdfFixer::processLines(std::list&lt;std::string&gt;&amp; lines) @@ -110,7 +110,7 @@ QdfFixer::processLines(std::list&lt;std::string&gt;&amp; lines)
110 static std::regex re_dict_end("^>>\n$"); 110 static std::regex re_dict_end("^>>\n$");
111 111
112 lineno = 0; 112 lineno = 0;
113 - for (auto line: lines) 113 + for (auto const& line: lines)
114 { 114 {
115 ++lineno; 115 ++lineno;
116 last_offset = offset; 116 last_offset = offset;
@@ -163,7 +163,7 @@ QdfFixer::processLines(std::list&lt;std::string&gt;&amp; lines) @@ -163,7 +163,7 @@ QdfFixer::processLines(std::list&lt;std::string&gt;&amp; lines)
163 // index. Make sure we get at least 1 byte even if 163 // index. Make sure we get at least 1 byte even if
164 // there are no object streams. 164 // there are no object streams.
165 int max_objects = 1; 165 int max_objects = 1;
166 - for (auto e: xref) 166 + for (auto const& e: xref)
167 { 167 {
168 if ((e.getType() == 2) && 168 if ((e.getType() == 2) &&
169 (e.getObjStreamIndex() > max_objects)) 169 (e.getObjStreamIndex() > max_objects))
@@ -258,7 +258,7 @@ QdfFixer::processLines(std::list&lt;std::string&gt;&amp; lines) @@ -258,7 +258,7 @@ QdfFixer::processLines(std::list&lt;std::string&gt;&amp; lines)
258 writeBinary(0, 1); 258 writeBinary(0, 1);
259 writeBinary(0, xref_f1_nbytes); 259 writeBinary(0, xref_f1_nbytes);
260 writeBinary(0, xref_f2_nbytes); 260 writeBinary(0, xref_f2_nbytes);
261 - for (auto x: xref) 261 + for (auto const& x: xref)
262 { 262 {
263 unsigned long long f1 = 0; 263 unsigned long long f1 = 0;
264 unsigned long long f2 = 0; 264 unsigned long long f2 = 0;
@@ -321,7 +321,7 @@ QdfFixer::processLines(std::list&lt;std::string&gt;&amp; lines) @@ -321,7 +321,7 @@ QdfFixer::processLines(std::list&lt;std::string&gt;&amp; lines)
321 { 321 {
322 auto n = xref.size(); 322 auto n = xref.size();
323 std::cout << "0 " << 1 + n << "\n0000000000 65535 f \n"; 323 std::cout << "0 " << 1 + n << "\n0000000000 65535 f \n";
324 - for (auto e: xref) 324 + for (auto const& e: xref)
325 { 325 {
326 std::cout << QUtil::int_to_string(e.getOffset(), 10) 326 std::cout << QUtil::int_to_string(e.getOffset(), 10)
327 << " 00000 n \n"; 327 << " 00000 n \n";
@@ -410,12 +410,12 @@ QdfFixer::writeOstream() @@ -410,12 +410,12 @@ QdfFixer::writeOstream()
410 std::cout << dict_data 410 std::cout << dict_data
411 << "stream\n" 411 << "stream\n"
412 << offsets; 412 << offsets;
413 - for (auto o: ostream) 413 + for (auto const& o: ostream)
414 { 414 {
415 std::cout << o; 415 std::cout << o;
416 } 416 }
417 417
418 - for (auto o: ostream_discarded) 418 + for (auto const& o: ostream_discarded)
419 { 419 {
420 offset -= QIntC::to_offset(o.length()); 420 offset -= QIntC::to_offset(o.length());
421 } 421 }
qpdf/qpdf.cc
@@ -3693,7 +3693,7 @@ static void do_json_objectinfo(QPDF&amp; pdf, Options&amp; o, JSON&amp; j) @@ -3693,7 +3693,7 @@ static void do_json_objectinfo(QPDF&amp; pdf, Options&amp; o, JSON&amp; j)
3693 std::set<QPDFObjGen> wanted_og = get_wanted_json_objects(o); 3693 std::set<QPDFObjGen> wanted_og = get_wanted_json_objects(o);
3694 JSON j_objectinfo = j.addDictionaryMember( 3694 JSON j_objectinfo = j.addDictionaryMember(
3695 "objectinfo", JSON::makeDictionary()); 3695 "objectinfo", JSON::makeDictionary());
3696 - for (auto obj: pdf.getAllObjects()) 3696 + for (auto& obj: pdf.getAllObjects())
3697 { 3697 {
3698 if (all_objects || wanted_og.count(obj.getObjGen())) 3698 if (all_objects || wanted_og.count(obj.getObjGen()))
3699 { 3699 {
@@ -4922,7 +4922,7 @@ static bool should_remove_unreferenced_resources(QPDF&amp; pdf, Options&amp; o) @@ -4922,7 +4922,7 @@ static bool should_remove_unreferenced_resources(QPDF&amp; pdf, Options&amp; o)
4922 } 4922 }
4923 if (xobject.isDictionary()) 4923 if (xobject.isDictionary())
4924 { 4924 {
4925 - for (auto k: xobject.getKeys()) 4925 + for (auto const& k: xobject.getKeys())
4926 { 4926 {
4927 QPDFObjectHandle xobj = xobject.getKey(k); 4927 QPDFObjectHandle xobj = xobject.getKey(k);
4928 if (xobj.isStream() && 4928 if (xobj.isStream() &&