diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-04-30 19:23:18 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-04-30 19:27:18 +0200 |
commit | 4f24617e1ea4ba7a6627a9c44304c6e0a0114249 (patch) | |
tree | 65c02e9e31cac60bac6f6aec165e8397dcde70e2 /libqpdf/QPDFObjectHandle.cc | |
parent | 7f023701dd843749cf878baabeb3d33917fda62f (diff) | |
download | qpdf-4f24617e1ea4ba7a6627a9c44304c6e0a0114249.tar.zst |
Code clean up: use range-style for loops wherever possible
Where not possible, use "auto" to get the iterator type.
Editorial note: I have avoid this change for a long time because of
not wanting to make gratuitous changes to version history, which can
obscure when certain changes were made, but with having recently
touched every single file to apply automatic code formatting and with
making several broad changes to the API, I decided it was time to take
the plunge and get rid of the older (pre-C++11) verbose iterator
syntax. The new code is just easier to read and understand, and in
many cases, it will be more effecient as fewer temporary copies are
being made.
m-holger, if you're reading, you can see that I've finally come
around. :-)
Diffstat (limited to 'libqpdf/QPDFObjectHandle.cc')
-rw-r--r-- | libqpdf/QPDFObjectHandle.cc | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index c156e627..76a6127e 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -1244,17 +1244,12 @@ QPDFObjectHandle::getResourceNames() return result; } std::set<std::string> keys = getKeys(); - for (std::set<std::string>::iterator iter = keys.begin(); - iter != keys.end(); - ++iter) { - std::string const& key = *iter; + for (auto const& key: keys) { QPDFObjectHandle val = getKey(key); if (val.isDictionary()) { std::set<std::string> val_keys = val.getKeys(); - for (std::set<std::string>::iterator i2 = val_keys.begin(); - i2 != val_keys.end(); - ++i2) { - result.insert(*i2); + for (auto const& val_key: val_keys) { + result.insert(val_key); } } } @@ -1620,10 +1615,7 @@ QPDFObjectHandle::arrayOrStreamToStreamArray( } bool first = true; - for (std::vector<QPDFObjectHandle>::iterator iter = result.begin(); - iter != result.end(); - ++iter) { - QPDFObjectHandle item = *iter; + for (auto const& item: result) { std::string og = QUtil::int_to_string(item.getObjectID()) + " " + QUtil::int_to_string(item.getGeneration()); if (first) { @@ -1660,11 +1652,9 @@ QPDFObjectHandle::addPageContents(QPDFObjectHandle new_contents, bool first) QTC::TC("qpdf", "QPDFObjectHandle prepend page contents"); content_streams.push_back(new_contents); } - for (std::vector<QPDFObjectHandle>::iterator iter = orig_contents.begin(); - iter != orig_contents.end(); - ++iter) { + for (auto const& iter: orig_contents) { QTC::TC("qpdf", "QPDFObjectHandle append page contents"); - content_streams.push_back(*iter); + content_streams.push_back(iter); } if (!first) { content_streams.push_back(new_contents); @@ -1865,14 +1855,11 @@ QPDFObjectHandle::pipeContentStreams( arrayOrStreamToStreamArray(description, all_description); bool need_newline = false; Pl_Buffer buf("concatenated content stream buffer"); - for (std::vector<QPDFObjectHandle>::iterator iter = streams.begin(); - iter != streams.end(); - ++iter) { + for (auto stream: streams) { if (need_newline) { buf.write(QUtil::unsigned_char_pointer("\n"), 1); } LastChar lc(&buf); - QPDFObjectHandle stream = *iter; std::string og = QUtil::int_to_string(stream.getObjectID()) + " " + QUtil::int_to_string(stream.getGeneration()); std::string w_description = "content stream object " + og; @@ -2920,13 +2907,11 @@ QPDFObjectHandle::copyObject( QTC::TC("qpdf", "QPDFObjectHandle clone dictionary"); std::set<std::string> keys = getKeys(); std::map<std::string, QPDFObjectHandle> items; - for (std::set<std::string>::iterator iter = keys.begin(); - iter != keys.end(); - ++iter) { - items[*iter] = getKey(*iter); + for (auto const& key: keys) { + items[key] = getKey(key); if ((!first_level_only) && - (cross_indirect || (!items[*iter].isIndirect()))) { - items[*iter].copyObject( + (cross_indirect || (!items[key].isIndirect()))) { + items[key].copyObject( visited, cross_indirect, first_level_only, stop_at_streams); } } |