mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-22 22:58:33 +00:00
Fix unnecessary copies in auto iter (fixes #426)
Also switch to colon-style iteration in some cases. Thanks to Dean Scarff for drawing this to my attention after detecting some unnecessary copies with https://clang.llvm.org/extra/clang-tidy/checks/performance-for-range-copy.html
This commit is contained in:
parent
b89b1d772d
commit
1a7d3700a6
@ -346,7 +346,7 @@ JSON::checkSchemaInternal(JSON_value* this_v, JSON_value* sch_v,
|
||||
if (sch_dict && (! pattern_key.empty()))
|
||||
{
|
||||
auto pattern_schema = sch_dict->members[pattern_key].getPointer();
|
||||
for (auto iter: this_dict->members)
|
||||
for (auto const& iter: this_dict->members)
|
||||
{
|
||||
std::string const& key = iter.first;
|
||||
checkSchemaInternal(
|
||||
|
@ -110,10 +110,9 @@ QPDFCryptoProvider::getRegisteredImpls()
|
||||
{
|
||||
std::set<std::string> result;
|
||||
QPDFCryptoProvider& p = getInstance();
|
||||
for (auto iter = p.m->providers.begin(); iter != p.m->providers.end();
|
||||
++iter)
|
||||
for (auto const& iter: p.m->providers)
|
||||
{
|
||||
result.insert((*iter).first);
|
||||
result.insert(iter.first);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -146,9 +146,8 @@ QPDF_Array::getElementsForShallowCopy() const
|
||||
void
|
||||
QPDF_Array::addExplicitElementsToList(std::list<QPDFObjectHandle>& l) const
|
||||
{
|
||||
for (auto iter = this->elements.begin();
|
||||
iter != this->elements.end(); ++iter)
|
||||
for (auto const& iter: this->elements)
|
||||
{
|
||||
l.push_back((*iter).second);
|
||||
l.push_back(iter.second);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ SparseOHArray::at(size_t idx) const
|
||||
throw std::logic_error(
|
||||
"INTERNAL ERROR: bounds error accessing SparseOHArray element");
|
||||
}
|
||||
auto iter = this->elements.find(idx);
|
||||
auto const& iter = this->elements.find(idx);
|
||||
if (iter == this->elements.end())
|
||||
{
|
||||
return QPDFObjectHandle::newNull();
|
||||
@ -57,10 +57,9 @@ SparseOHArray::remove_last()
|
||||
void
|
||||
SparseOHArray::releaseResolved()
|
||||
{
|
||||
for (auto iter = this->elements.begin();
|
||||
iter != this->elements.end(); ++iter)
|
||||
for (auto iter: this->elements)
|
||||
{
|
||||
QPDFObjectHandle::ReleaseResolver::releaseResolved((*iter).second);
|
||||
QPDFObjectHandle::ReleaseResolver::releaseResolved(iter.second);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,16 +88,15 @@ SparseOHArray::erase(size_t idx)
|
||||
throw std::logic_error("bounds error erasing item from SparseOHArray");
|
||||
}
|
||||
decltype(this->elements) dest;
|
||||
for (auto iter = this->elements.begin();
|
||||
iter != this->elements.end(); ++iter)
|
||||
for (auto const& iter: this->elements)
|
||||
{
|
||||
if ((*iter).first < idx)
|
||||
if (iter.first < idx)
|
||||
{
|
||||
dest.insert(*iter);
|
||||
dest.insert(iter);
|
||||
}
|
||||
else if ((*iter).first > idx)
|
||||
else if (iter.first > idx)
|
||||
{
|
||||
dest[(*iter).first - 1] = (*iter).second;
|
||||
dest[iter.first - 1] = iter.second;
|
||||
}
|
||||
}
|
||||
this->elements = dest;
|
||||
@ -120,16 +118,15 @@ SparseOHArray::insert(size_t idx, QPDFObjectHandle oh)
|
||||
else
|
||||
{
|
||||
decltype(this->elements) dest;
|
||||
for (auto iter = this->elements.begin();
|
||||
iter != this->elements.end(); ++iter)
|
||||
for (auto const& iter: this->elements)
|
||||
{
|
||||
if ((*iter).first < idx)
|
||||
if (iter.first < idx)
|
||||
{
|
||||
dest.insert(*iter);
|
||||
dest.insert(iter);
|
||||
}
|
||||
else
|
||||
{
|
||||
dest[(*iter).first + 1] = (*iter).second;
|
||||
dest[iter.first + 1] = iter.second;
|
||||
}
|
||||
}
|
||||
this->elements = dest;
|
||||
|
@ -387,13 +387,12 @@ QdfFixer::writeOstream()
|
||||
auto onum = ostream_id;
|
||||
std::string offsets;
|
||||
auto n = ostream_offsets.size();
|
||||
for (auto iter = ostream_offsets.begin();
|
||||
iter != ostream_offsets.end(); ++iter)
|
||||
for (auto iter: ostream_offsets)
|
||||
{
|
||||
(*iter) -= QIntC::to_offset(first);
|
||||
iter -= QIntC::to_offset(first);
|
||||
++onum;
|
||||
offsets += QUtil::int_to_string(onum) + " " +
|
||||
QUtil::int_to_string(*iter) + "\n";
|
||||
QUtil::int_to_string(iter) + "\n";
|
||||
}
|
||||
auto offset_adjust = QIntC::to_offset(offsets.size());
|
||||
first += offset_adjust;
|
||||
|
@ -1694,11 +1694,11 @@ ArgParser::argShowCrypto()
|
||||
auto crypto = QPDFCryptoProvider::getRegisteredImpls();
|
||||
std::string default_crypto = QPDFCryptoProvider::getDefaultProvider();
|
||||
std::cout << default_crypto << std::endl;
|
||||
for (auto iter = crypto.begin(); iter != crypto.end(); ++iter)
|
||||
for (auto const& iter: crypto)
|
||||
{
|
||||
if (*iter != default_crypto)
|
||||
if (iter != default_crypto)
|
||||
{
|
||||
std::cout << *iter << std::endl;
|
||||
std::cout << iter << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3646,7 +3646,7 @@ static std::set<QPDFObjGen>
|
||||
get_wanted_json_objects(Options& o)
|
||||
{
|
||||
std::set<QPDFObjGen> wanted_og;
|
||||
for (auto iter: o.json_objects)
|
||||
for (auto const& iter: o.json_objects)
|
||||
{
|
||||
bool trailer;
|
||||
int obj = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user