aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2020-04-10 16:07:23 +0200
committerJay Berkenbilt <ejb@ql.org>2020-04-10 19:30:33 +0200
commit578c5ac66c80cd1bfb43206dbba091a3985bb4bc (patch)
tree11220d51e5f647689d84ce347573d51f9640ac9f
parent821a70185135df50a28ad92733f82fbe5b562556 (diff)
downloadqpdf-578c5ac66c80cd1bfb43206dbba091a3985bb4bc.tar.zst
Use more references when iterating
When possible, use `for (auto&` or `for (auto const&` when iterating using C++-11 style iterators.
-rw-r--r--libqpdf/SparseOHArray.cc2
-rw-r--r--libtests/cxx11.cc2
-rw-r--r--qpdf/fix-qdf.cc12
-rw-r--r--qpdf/qpdf.cc4
4 files changed, 10 insertions, 10 deletions
diff --git a/libqpdf/SparseOHArray.cc b/libqpdf/SparseOHArray.cc
index c8aaefa8..972376b1 100644
--- a/libqpdf/SparseOHArray.cc
+++ b/libqpdf/SparseOHArray.cc
@@ -57,7 +57,7 @@ SparseOHArray::remove_last()
void
SparseOHArray::releaseResolved()
{
- for (auto iter: this->elements)
+ for (auto& iter: this->elements)
{
QPDFObjectHandle::ReleaseResolver::releaseResolved(iter.second);
}
diff --git a/libtests/cxx11.cc b/libtests/cxx11.cc
index 91ed7b15..ba4525ed 100644
--- a/libtests/cxx11.cc
+++ b/libtests/cxx11.cc
@@ -105,7 +105,7 @@ void do_iteration()
std::vector<int> v = { 1, 2, 3, 4 };
assert(v.size() == 4);
int sum = 0;
- for (auto i: v)
+ for (auto& i: v)
{
sum += i;
}
diff --git a/qpdf/fix-qdf.cc b/qpdf/fix-qdf.cc
index c50f7b5a..c83b495a 100644
--- a/qpdf/fix-qdf.cc
+++ b/qpdf/fix-qdf.cc
@@ -110,7 +110,7 @@ QdfFixer::processLines(std::list<std::string>& lines)
static std::regex re_dict_end("^>>\n$");
lineno = 0;
- for (auto line: lines)
+ for (auto const& line: lines)
{
++lineno;
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
// there are no object streams.
int max_objects = 1;
- for (auto e: xref)
+ for (auto const& e: xref)
{
if ((e.getType() == 2) &&
(e.getObjStreamIndex() > max_objects))
@@ -258,7 +258,7 @@ QdfFixer::processLines(std::list<std::string>& lines)
writeBinary(0, 1);
writeBinary(0, xref_f1_nbytes);
writeBinary(0, xref_f2_nbytes);
- for (auto x: xref)
+ for (auto const& x: xref)
{
unsigned long long f1 = 0;
unsigned long long f2 = 0;
@@ -321,7 +321,7 @@ QdfFixer::processLines(std::list<std::string>& lines)
{
auto n = xref.size();
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)
<< " 00000 n \n";
@@ -410,12 +410,12 @@ QdfFixer::writeOstream()
std::cout << dict_data
<< "stream\n"
<< offsets;
- for (auto o: ostream)
+ for (auto const& o: ostream)
{
std::cout << o;
}
- for (auto o: ostream_discarded)
+ for (auto const& o: ostream_discarded)
{
offset -= QIntC::to_offset(o.length());
}
diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc
index 35267e85..02a95c73 100644
--- a/qpdf/qpdf.cc
+++ b/qpdf/qpdf.cc
@@ -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);
JSON j_objectinfo = j.addDictionaryMember(
"objectinfo", JSON::makeDictionary());
- for (auto obj: pdf.getAllObjects())
+ for (auto& obj: pdf.getAllObjects())
{
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())
{
- for (auto k: xobject.getKeys())
+ for (auto const& k: xobject.getKeys())
{
QPDFObjectHandle xobj = xobject.getKey(k);
if (xobj.isStream() &&