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