2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

Add private method QPDF::ObjCache::update

Add a new obj_cache entry or update an existing entry in place.
This commit is contained in:
m-holger 2022-08-10 13:16:06 +01:00
parent c0cd72a3ee
commit 556c34f0f2
2 changed files with 23 additions and 2 deletions

View File

@ -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(

View File

@ -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