diff options
author | m-holger <m-holger@kubitscheck.org> | 2022-08-10 14:16:06 +0200 |
---|---|---|
committer | m-holger <m-holger@kubitscheck.org> | 2022-09-01 15:30:26 +0200 |
commit | 556c34f0f225bfc6eaeb617693e0161fbce5f2f3 (patch) | |
tree | e0f5a54a38c8aeda4f4f75ff1382841e9eed5ea2 | |
parent | c0cd72a3eef996e597ba82b784de029ec6d88707 (diff) | |
download | qpdf-556c34f0f225bfc6eaeb617693e0161fbce5f2f3.tar.zst |
Add private method QPDF::ObjCache::update
Add a new obj_cache entry or update an existing entry in place.
-rw-r--r-- | include/qpdf/QPDF.hh | 5 | ||||
-rw-r--r-- | libqpdf/QPDF.cc | 20 |
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 |