Commit 578c5ac66c80cd1bfb43206dbba091a3985bb4bc
1 parent
821a7018
Use more references when iterating
When possible, use `for (auto&` or `for (auto const&` when iterating using C++-11 style iterators.
Showing
4 changed files
with
10 additions
and
10 deletions
libqpdf/SparseOHArray.cc
libtests/cxx11.cc
qpdf/fix-qdf.cc
| ... | ... | @@ -110,7 +110,7 @@ QdfFixer::processLines(std::list<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& 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& pdf, Options& o, JSON& 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& pdf, Options& 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() && | ... | ... |