Commit 742cc7d87b574dea708db69cdec75e8e2b54f64a
1 parent
fa03ed38
Add temporary methods QPDF::Xref_table::size and as_map
Also, remove redundant clearing of the xref tabl during QPDF destruction.
Showing
3 changed files
with
21 additions
and
11 deletions
libqpdf/QPDF.cc
| @@ -227,9 +227,6 @@ QPDF::~QPDF() | @@ -227,9 +227,6 @@ QPDF::~QPDF() | ||
| 227 | // are reachable from this object to release their association with this QPDF. Direct objects | 227 | // are reachable from this object to release their association with this QPDF. Direct objects |
| 228 | // are not destroyed since they can be moved to other QPDF objects safely. | 228 | // are not destroyed since they can be moved to other QPDF objects safely. |
| 229 | 229 | ||
| 230 | - // At this point, obviously no one is still using the QPDF object, but we'll explicitly clear | ||
| 231 | - // the xref table anyway just to prevent any possibility of resolve() succeeding. | ||
| 232 | - m->xref_table.clear(); | ||
| 233 | for (auto const& iter: m->obj_cache) { | 230 | for (auto const& iter: m->obj_cache) { |
| 234 | iter.second.object->disconnect(); | 231 | iter.second.object->disconnect(); |
| 235 | if (iter.second.object->getTypeCode() != ::ot_null) { | 232 | if (iter.second.object->getTypeCode() != ::ot_null) { |
| @@ -1651,7 +1648,7 @@ QPDF::recoverStreamLength( | @@ -1651,7 +1648,7 @@ QPDF::recoverStreamLength( | ||
| 1651 | QPDFObjGen found_og; | 1648 | QPDFObjGen found_og; |
| 1652 | 1649 | ||
| 1653 | // Make sure this is inside this object | 1650 | // Make sure this is inside this object |
| 1654 | - for (auto const& [current_og, entry]: m->xref_table) { | 1651 | + for (auto const& [current_og, entry]: m->xref_table.as_map()) { |
| 1655 | if (entry.getType() == 1) { | 1652 | if (entry.getType() == 1) { |
| 1656 | qpdf_offset_t obj_offset = entry.getOffset(); | 1653 | qpdf_offset_t obj_offset = entry.getOffset(); |
| 1657 | if (found_offset < obj_offset && obj_offset < end) { | 1654 | if (found_offset < obj_offset && obj_offset < end) { |
| @@ -1984,9 +1981,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | @@ -1984,9 +1981,8 @@ QPDF::resolveObjectsInStream(int obj_stream_number) | ||
| 1984 | m->last_object_description += "object "; | 1981 | m->last_object_description += "object "; |
| 1985 | for (auto const& iter: offsets) { | 1982 | for (auto const& iter: offsets) { |
| 1986 | QPDFObjGen og(iter.first, 0); | 1983 | QPDFObjGen og(iter.first, 0); |
| 1987 | - auto entry = m->xref_table.find(og); | ||
| 1988 | - if (entry != m->xref_table.end() && entry->second.getType() == 2 && | ||
| 1989 | - entry->second.getObjStreamNumber() == obj_stream_number) { | 1984 | + if (m->xref_table.type(og) == 2 && |
| 1985 | + m->xref_table.stream_number(og.getObj()) == obj_stream_number) { | ||
| 1990 | int offset = iter.second; | 1986 | int offset = iter.second; |
| 1991 | input->seek(offset, SEEK_SET); | 1987 | input->seek(offset, SEEK_SET); |
| 1992 | QPDFObjectHandle oh = readObjectInStream(input, iter.first); | 1988 | QPDFObjectHandle oh = readObjectInStream(input, iter.first); |
| @@ -2560,7 +2556,7 @@ QPDF::getXRefTableInternal() | @@ -2560,7 +2556,7 @@ QPDF::getXRefTableInternal() | ||
| 2560 | throw std::logic_error("QPDF::getXRefTable called before parsing."); | 2556 | throw std::logic_error("QPDF::getXRefTable called before parsing."); |
| 2561 | } | 2557 | } |
| 2562 | 2558 | ||
| 2563 | - return m->xref_table; | 2559 | + return m->xref_table.as_map(); |
| 2564 | } | 2560 | } |
| 2565 | 2561 | ||
| 2566 | size_t | 2562 | size_t |
| @@ -2568,7 +2564,7 @@ QPDF::tableSize() | @@ -2568,7 +2564,7 @@ QPDF::tableSize() | ||
| 2568 | { | 2564 | { |
| 2569 | // If obj_cache is dense, accommodate all object in tables,else accommodate only original | 2565 | // If obj_cache is dense, accommodate all object in tables,else accommodate only original |
| 2570 | // objects. | 2566 | // objects. |
| 2571 | - auto max_xref = m->xref_table.size() ? m->xref_table.crbegin()->first.getObj() : 0; | 2567 | + auto max_xref = m->xref_table.size() ? m->xref_table.as_map().crbegin()->first.getObj() : 0; |
| 2572 | auto max_obj = m->obj_cache.size() ? m->obj_cache.crbegin()->first.getObj() : 0; | 2568 | auto max_obj = m->obj_cache.size() ? m->obj_cache.crbegin()->first.getObj() : 0; |
| 2573 | auto max_id = std::numeric_limits<int>::max() - 1; | 2569 | auto max_id = std::numeric_limits<int>::max() - 1; |
| 2574 | if (max_obj >= max_id || max_xref >= max_id) { | 2570 | if (max_obj >= max_id || max_xref >= max_id) { |
libqpdf/QPDF_linearization.cc
| @@ -486,7 +486,7 @@ QPDF::checkLinearizationInternal() | @@ -486,7 +486,7 @@ QPDF::checkLinearizationInternal() | ||
| 486 | // to figure out which objects are compressed and which are uncompressed. | 486 | // to figure out which objects are compressed and which are uncompressed. |
| 487 | { // local scope | 487 | { // local scope |
| 488 | std::map<int, int> object_stream_data; | 488 | std::map<int, int> object_stream_data; |
| 489 | - for (auto const& iter: m->xref_table) { | 489 | + for (auto const& iter: m->xref_table.as_map()) { |
| 490 | QPDFObjGen const& og = iter.first; | 490 | QPDFObjGen const& og = iter.first; |
| 491 | QPDFXRefEntry const& entry = iter.second; | 491 | QPDFXRefEntry const& entry = iter.second; |
| 492 | if (entry.getType() == 2) { | 492 | if (entry.getType() == 2) { |
libqpdf/qpdf/QPDF_private.hh
| @@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
| 4 | #include <qpdf/QPDF.hh> | 4 | #include <qpdf/QPDF.hh> |
| 5 | 5 | ||
| 6 | // Xref_table encapsulates the pdf's xref table and trailer. | 6 | // Xref_table encapsulates the pdf's xref table and trailer. |
| 7 | -class QPDF::Xref_table: public std::map<QPDFObjGen, QPDFXRefEntry> | 7 | +class QPDF::Xref_table: std::map<QPDFObjGen, QPDFXRefEntry> |
| 8 | { | 8 | { |
| 9 | public: | 9 | public: |
| 10 | Xref_table(QPDF& qpdf, InputSource* const& file) : | 10 | Xref_table(QPDF& qpdf, InputSource* const& file) : |
| @@ -50,6 +50,20 @@ class QPDF::Xref_table: public std::map<QPDFObjGen, QPDFXRefEntry> | @@ -50,6 +50,20 @@ class QPDF::Xref_table: public std::map<QPDFObjGen, QPDFXRefEntry> | ||
| 50 | return it == end() ? 0 : it->second.getObjStreamIndex(); | 50 | return it == end() ? 0 : it->second.getObjStreamIndex(); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | + // Temporary access to underlying map | ||
| 54 | + std::map<QPDFObjGen, QPDFXRefEntry> const& | ||
| 55 | + as_map() | ||
| 56 | + { | ||
| 57 | + return *this; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + // Temporary access to underlying map size | ||
| 61 | + size_t | ||
| 62 | + size() const noexcept | ||
| 63 | + { | ||
| 64 | + return trailer ? std::map<QPDFObjGen, QPDFXRefEntry>::size() : 0; | ||
| 65 | + } | ||
| 66 | + | ||
| 53 | QPDFObjectHandle trailer; | 67 | QPDFObjectHandle trailer; |
| 54 | bool reconstructed{false}; | 68 | bool reconstructed{false}; |
| 55 | // Various tables are indexed by object id, with potential size id + 1 | 69 | // Various tables are indexed by object id, with potential size id + 1 |