diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 9df31555..e7a76b80 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -597,9 +597,15 @@ QPDF::getObjectByID(int id, int gen) } void -QPDF::replaceObject(int objid, int generation, QPDFObjectHandle oh) +QPDF::replaceObject(int id, int gen, QPDFObjectHandle replacement) { - replaceObject(QPDFObjGen(objid, generation), oh); + m->objects.replace(QPDFObjGen(id, gen), replacement); +} + +void +QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle replacement) +{ + m->objects.replace(og, replacement); } void @@ -610,7 +616,7 @@ QPDF::replaceReserved(QPDFObjectHandle reserved, QPDFObjectHandle replacement) if (!(tc == ::ot_reserved || tc == ::ot_null)) { throw std::logic_error("replaceReserved called with non-reserved object"); } - replaceObject(reserved.getObjGen(), replacement); + m->objects.replace(reserved.getObjGen(), replacement); } QPDFObjectHandle diff --git a/libqpdf/QPDF_objects.cc b/libqpdf/QPDF_objects.cc index f7f17ec9..920517db 100644 --- a/libqpdf/QPDF_objects.cc +++ b/libqpdf/QPDF_objects.cc @@ -1758,13 +1758,13 @@ Objects::get_for_json(int id, int gen) } void -QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh) +Objects::replace(QPDFObjGen og, QPDFObjectHandle oh) { if (!oh || (oh.isIndirect() && !(oh.isStream() && oh.getObjGen() == og))) { QTC::TC("qpdf", "QPDF replaceObject called with indirect object"); throw std::logic_error("QPDF::replaceObject called with indirect object handle"); } - objects().update_table(og, oh.getObj()); + update_table(og, oh.getObj()); } void diff --git a/libqpdf/qpdf/QPDF_objects.hh b/libqpdf/qpdf/QPDF_objects.hh index c32a8853..ad12f9c4 100644 --- a/libqpdf/qpdf/QPDF_objects.hh +++ b/libqpdf/qpdf/QPDF_objects.hh @@ -441,6 +441,10 @@ class QPDF::Objects return get(QPDFObjGen(id, gen)); } + void erase(QPDFObjGen og); + + void replace(QPDFObjGen og, QPDFObjectHandle oh); + std::map obj_cache; QPDFObjectHandle readObjectInStream(std::shared_ptr& input, int obj); @@ -469,7 +473,6 @@ class QPDF::Objects size_t table_size(); private: - void erase(QPDFObjGen og); bool cached(QPDFObjGen og); bool unresolved(QPDFObjGen og);