aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/qpdf/QPDF.hh5
-rw-r--r--libqpdf/QPDF.cc20
2 files changed, 23 insertions, 2 deletions
diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh
index ee265cec..c187d53f 100644
--- a/include/qpdf/QPDF.hh
+++ b/include/qpdf/QPDF.hh
@@ -1177,6 +1177,11 @@ class QPDF
newIndirect(QPDFObjGen const&, std::shared_ptr<QPDFObject> const&);
bool isCached(QPDFObjGen const& og);
bool isUnresolved(QPDFObjGen const& og);
+ void updateCache(
+ QPDFObjGen const& og,
+ std::shared_ptr<QPDFObject> const& object,
+ qpdf_offset_t end_before_space,
+ qpdf_offset_t end_after_space);
// Calls finish() on the pipeline when done but does not delete it
bool pipeStreamData(
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index d877c14a..80cc34cc 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -2111,6 +2111,23 @@ QPDF::newIndirect(QPDFObjGen const& og, std::shared_ptr<QPDFObject> const& obj)
return QPDFObjectHandle::Factory::newIndirect(this, og, obj);
}
+void
+QPDF::updateCache(
+ QPDFObjGen const& og,
+ std::shared_ptr<QPDFObject> const& object,
+ qpdf_offset_t end_before_space,
+ qpdf_offset_t end_after_space)
+{
+ if (isCached(og)) {
+ auto& cache = m->obj_cache[og];
+ cache.object->assign(object);
+ cache.end_before_space = end_before_space;
+ cache.end_after_space = end_after_space;
+ } else {
+ m->obj_cache[og] = ObjCache(object, end_before_space, end_after_space);
+ }
+}
+
bool
QPDF::isCached(QPDFObjGen const& og)
{
@@ -2199,8 +2216,7 @@ QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh)
resolve(og);
// Replace the object in the object cache
- m->obj_cache[og].object->assign(
- QPDFObjectHandle::ObjAccessor::getObject(oh));
+ updateCache(og, QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1);
}
void