2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-08 21:22:25 +00:00

Use more references when iterating

When possible, use `for (auto&` or `for (auto const&` when iterating
using C++-11 style iterators.
This commit is contained in:
Jay Berkenbilt 2020-04-10 10:07:23 -04:00
parent 821a701851
commit 578c5ac66c
4 changed files with 10 additions and 10 deletions

View File

@ -57,7 +57,7 @@ SparseOHArray::remove_last()
void void
SparseOHArray::releaseResolved() SparseOHArray::releaseResolved()
{ {
for (auto iter: this->elements) for (auto& iter: this->elements)
{ {
QPDFObjectHandle::ReleaseResolver::releaseResolved(iter.second); QPDFObjectHandle::ReleaseResolver::releaseResolved(iter.second);
} }

View File

@ -105,7 +105,7 @@ void do_iteration()
std::vector<int> v = { 1, 2, 3, 4 }; std::vector<int> v = { 1, 2, 3, 4 };
assert(v.size() == 4); assert(v.size() == 4);
int sum = 0; int sum = 0;
for (auto i: v) for (auto& i: v)
{ {
sum += i; sum += i;
} }

View File

@ -110,7 +110,7 @@ QdfFixer::processLines(std::list<std::string>& lines)
static std::regex re_dict_end("^>>\n$"); static std::regex re_dict_end("^>>\n$");
lineno = 0; lineno = 0;
for (auto line: lines) for (auto const& line: lines)
{ {
++lineno; ++lineno;
last_offset = offset; last_offset = offset;
@ -163,7 +163,7 @@ QdfFixer::processLines(std::list<std::string>& lines)
// index. Make sure we get at least 1 byte even if // index. Make sure we get at least 1 byte even if
// there are no object streams. // there are no object streams.
int max_objects = 1; int max_objects = 1;
for (auto e: xref) for (auto const& e: xref)
{ {
if ((e.getType() == 2) && if ((e.getType() == 2) &&
(e.getObjStreamIndex() > max_objects)) (e.getObjStreamIndex() > max_objects))
@ -258,7 +258,7 @@ QdfFixer::processLines(std::list<std::string>& lines)
writeBinary(0, 1); writeBinary(0, 1);
writeBinary(0, xref_f1_nbytes); writeBinary(0, xref_f1_nbytes);
writeBinary(0, xref_f2_nbytes); writeBinary(0, xref_f2_nbytes);
for (auto x: xref) for (auto const& x: xref)
{ {
unsigned long long f1 = 0; unsigned long long f1 = 0;
unsigned long long f2 = 0; unsigned long long f2 = 0;
@ -321,7 +321,7 @@ QdfFixer::processLines(std::list<std::string>& lines)
{ {
auto n = xref.size(); auto n = xref.size();
std::cout << "0 " << 1 + n << "\n0000000000 65535 f \n"; std::cout << "0 " << 1 + n << "\n0000000000 65535 f \n";
for (auto e: xref) for (auto const& e: xref)
{ {
std::cout << QUtil::int_to_string(e.getOffset(), 10) std::cout << QUtil::int_to_string(e.getOffset(), 10)
<< " 00000 n \n"; << " 00000 n \n";
@ -410,12 +410,12 @@ QdfFixer::writeOstream()
std::cout << dict_data std::cout << dict_data
<< "stream\n" << "stream\n"
<< offsets; << offsets;
for (auto o: ostream) for (auto const& o: ostream)
{ {
std::cout << o; std::cout << o;
} }
for (auto o: ostream_discarded) for (auto const& o: ostream_discarded)
{ {
offset -= QIntC::to_offset(o.length()); offset -= QIntC::to_offset(o.length());
} }

View File

@ -3693,7 +3693,7 @@ static void do_json_objectinfo(QPDF& pdf, Options& o, JSON& j)
std::set<QPDFObjGen> wanted_og = get_wanted_json_objects(o); std::set<QPDFObjGen> wanted_og = get_wanted_json_objects(o);
JSON j_objectinfo = j.addDictionaryMember( JSON j_objectinfo = j.addDictionaryMember(
"objectinfo", JSON::makeDictionary()); "objectinfo", JSON::makeDictionary());
for (auto obj: pdf.getAllObjects()) for (auto& obj: pdf.getAllObjects())
{ {
if (all_objects || wanted_og.count(obj.getObjGen())) if (all_objects || wanted_og.count(obj.getObjGen()))
{ {
@ -4922,7 +4922,7 @@ static bool should_remove_unreferenced_resources(QPDF& pdf, Options& o)
} }
if (xobject.isDictionary()) if (xobject.isDictionary())
{ {
for (auto k: xobject.getKeys()) for (auto const& k: xobject.getKeys())
{ {
QPDFObjectHandle xobj = xobject.getKey(k); QPDFObjectHandle xobj = xobject.getKey(k);
if (xobj.isStream() && if (xobj.isStream() &&