Commit 336d7833250b9d8d8a28a6f232f659b765925593

Authored by m-holger
1 parent 113ea4e7

Move calculations from QPDF::getObjectCount to Objects::next_id

include/qpdf/QPDF.hh
... ... @@ -645,7 +645,7 @@ class QPDF
645 645 QPDF_DLL
646 646 void fixDanglingReferences(bool force = false);
647 647  
648   - // Return the approximate number of indirect objects. It is/ approximate because not all objects
  648 + // Return the approximate number of indirect objects. It is approximate because not all objects
649 649 // in the file are preserved in all cases, and gaps in object numbering are not preserved.
650 650 QPDF_DLL
651 651 size_t getObjectCount();
... ...
libqpdf/QPDF.cc
... ... @@ -492,12 +492,7 @@ QPDF::getObjectCount()
492 492 // This method returns the next available indirect object number. makeIndirectObject uses it for
493 493 // this purpose. After fixDanglingReferences is called, all objects in the xref table will also
494 494 // be in obj_cache.
495   - fixDanglingReferences();
496   - QPDFObjGen og;
497   - if (!m->objects.obj_cache.empty()) {
498   - og = (*(m->objects.obj_cache.rbegin())).first;
499   - }
500   - return toS(og.getObj());
  495 + return toS(m->objects.next_id().getObj() - 1);
501 496 }
502 497  
503 498 std::vector<QPDFObjectHandle>
... ...
libqpdf/QPDF_objects.cc
... ... @@ -1712,7 +1712,12 @@ Objects::unresolved(QPDFObjGen og)
1712 1712 QPDFObjGen
1713 1713 Objects::next_id()
1714 1714 {
1715   - int max_objid = toI(qpdf.getObjectCount());
  1715 + qpdf.fixDanglingReferences();
  1716 + QPDFObjGen og;
  1717 + if (!obj_cache.empty()) {
  1718 + og = (*(m->objects.obj_cache.rbegin())).first;
  1719 + }
  1720 + int max_objid = og.getObj();
1716 1721 if (max_objid == std::numeric_limits<int>::max()) {
1717 1722 throw std::range_error("max object id is too high to create new objects");
1718 1723 }
... ...