2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +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&); newIndirect(QPDFObjGen const&, std::shared_ptr<QPDFObject> const&);
bool isCached(QPDFObjGen const& og); bool isCached(QPDFObjGen const& og);
bool isUnresolved(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 // Calls finish() on the pipeline when done but does not delete it
bool pipeStreamData( 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); 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 bool
QPDF::isCached(QPDFObjGen const& og) QPDF::isCached(QPDFObjGen const& og)
{ {
@ -2199,8 +2216,7 @@ QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh)
resolve(og); resolve(og);
// Replace the object in the object cache // Replace the object in the object cache
m->obj_cache[og].object->assign( updateCache(og, QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1);
QPDFObjectHandle::ObjAccessor::getObject(oh));
} }
void void