mirror of https://github.com/qpdf/qpdf.git
Improve efficiency of fixDanglingReferences
This commit is contained in:
parent
5187a3ec85
commit
522d2b2227
|
@ -20,6 +20,7 @@
|
|||
#include <qpdf/QPDF_Null.hh>
|
||||
#include <qpdf/QPDF_Dictionary.hh>
|
||||
#include <qpdf/QPDF_Stream.hh>
|
||||
#include <qpdf/QPDF_Array.hh>
|
||||
|
||||
std::string QPDF::qpdf_version = "8.4.2";
|
||||
|
||||
|
@ -1349,13 +1350,10 @@ QPDF::fixDanglingReferences(bool force)
|
|||
}
|
||||
else if (obj.isArray())
|
||||
{
|
||||
std::vector<QPDFObjectHandle> elements = obj.getArrayAsVector();
|
||||
for (std::vector<QPDFObjectHandle>::iterator iter =
|
||||
elements.begin();
|
||||
iter != elements.end(); ++iter)
|
||||
{
|
||||
to_check.push_back(*iter);
|
||||
}
|
||||
QPDF_Array* arr =
|
||||
dynamic_cast<QPDF_Array*>(
|
||||
QPDFObjectHandle::ObjAccessor::getObject(obj).getPointer());
|
||||
arr->addExplicitElementsToList(to_check);
|
||||
}
|
||||
for (std::list<QPDFObjectHandle>::iterator iter = to_check.begin();
|
||||
iter != to_check.end(); ++iter)
|
||||
|
|
|
@ -142,3 +142,14 @@ QPDF_Array::getElementsForShallowCopy() const
|
|||
{
|
||||
return this->elements;
|
||||
}
|
||||
|
||||
void
|
||||
QPDF_Array::addExplicitElementsToList(std::list<QPDFObjectHandle>& l) const
|
||||
{
|
||||
for (std::map<size_t, QPDFObjectHandle>::const_iterator iter =
|
||||
this->elements.begin();
|
||||
iter != this->elements.end(); ++iter)
|
||||
{
|
||||
l.push_back((*iter).second);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,3 +141,15 @@ SparseOHArray::insert(size_t idx, QPDFObjectHandle oh)
|
|||
++this->n_elements;
|
||||
}
|
||||
}
|
||||
|
||||
SparseOHArray::const_iterator
|
||||
SparseOHArray::begin() const
|
||||
{
|
||||
return this->elements.begin();
|
||||
}
|
||||
|
||||
SparseOHArray::const_iterator
|
||||
SparseOHArray::end() const
|
||||
{
|
||||
return this->elements.end();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <qpdf/QPDFObject.hh>
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <qpdf/SparseOHArray.hh>
|
||||
|
||||
class QPDF_Array: public QPDFObject
|
||||
|
@ -28,7 +29,11 @@ class QPDF_Array: public QPDFObject
|
|||
void appendItem(QPDFObjectHandle const& item);
|
||||
void eraseItem(int at);
|
||||
|
||||
// Helper methods for QPDF and QPDFObjectHandle -- these are
|
||||
// public methods since the whole class is not part of the public
|
||||
// API. Otherwise, these would be wrapped in accessor classes.
|
||||
SparseOHArray const& getElementsForShallowCopy() const;
|
||||
void addExplicitElementsToList(std::list<QPDFObjectHandle>&) const;
|
||||
|
||||
protected:
|
||||
virtual void releaseResolved();
|
||||
|
|
|
@ -26,6 +26,12 @@ class SparseOHArray
|
|||
QPDF_DLL
|
||||
void insert(size_t idx, QPDFObjectHandle oh);
|
||||
|
||||
typedef std::map<size_t, QPDFObjectHandle>::const_iterator const_iterator;
|
||||
QPDF_DLL
|
||||
const_iterator begin() const;
|
||||
QPDF_DLL
|
||||
const_iterator end() const;
|
||||
|
||||
private:
|
||||
std::map<size_t, QPDFObjectHandle> elements;
|
||||
size_t n_elements;
|
||||
|
|
Loading…
Reference in New Issue