Commit 556c34f0f225bfc6eaeb617693e0161fbce5f2f3

Authored by m-holger
1 parent c0cd72a3

Add private method QPDF::ObjCache::update

Add a new obj_cache entry or update an existing entry in place.
include/qpdf/QPDF.hh
@@ -1177,6 +1177,11 @@ class QPDF @@ -1177,6 +1177,11 @@ class QPDF
1177 newIndirect(QPDFObjGen const&, std::shared_ptr<QPDFObject> const&); 1177 newIndirect(QPDFObjGen const&, std::shared_ptr<QPDFObject> const&);
1178 bool isCached(QPDFObjGen const& og); 1178 bool isCached(QPDFObjGen const& og);
1179 bool isUnresolved(QPDFObjGen const& og); 1179 bool isUnresolved(QPDFObjGen const& og);
  1180 + void updateCache(
  1181 + QPDFObjGen const& og,
  1182 + std::shared_ptr<QPDFObject> const& object,
  1183 + qpdf_offset_t end_before_space,
  1184 + qpdf_offset_t end_after_space);
1180 1185
1181 // Calls finish() on the pipeline when done but does not delete it 1186 // Calls finish() on the pipeline when done but does not delete it
1182 bool pipeStreamData( 1187 bool pipeStreamData(
libqpdf/QPDF.cc
@@ -2111,6 +2111,23 @@ QPDF::newIndirect(QPDFObjGen const&amp; og, std::shared_ptr&lt;QPDFObject&gt; const&amp; obj) @@ -2111,6 +2111,23 @@ QPDF::newIndirect(QPDFObjGen const&amp; og, std::shared_ptr&lt;QPDFObject&gt; const&amp; obj)
2111 return QPDFObjectHandle::Factory::newIndirect(this, og, obj); 2111 return QPDFObjectHandle::Factory::newIndirect(this, og, obj);
2112 } 2112 }
2113 2113
  2114 +void
  2115 +QPDF::updateCache(
  2116 + QPDFObjGen const& og,
  2117 + std::shared_ptr<QPDFObject> const& object,
  2118 + qpdf_offset_t end_before_space,
  2119 + qpdf_offset_t end_after_space)
  2120 +{
  2121 + if (isCached(og)) {
  2122 + auto& cache = m->obj_cache[og];
  2123 + cache.object->assign(object);
  2124 + cache.end_before_space = end_before_space;
  2125 + cache.end_after_space = end_after_space;
  2126 + } else {
  2127 + m->obj_cache[og] = ObjCache(object, end_before_space, end_after_space);
  2128 + }
  2129 +}
  2130 +
2114 bool 2131 bool
2115 QPDF::isCached(QPDFObjGen const& og) 2132 QPDF::isCached(QPDFObjGen const& og)
2116 { 2133 {
@@ -2199,8 +2216,7 @@ QPDF::replaceObject(QPDFObjGen const&amp; og, QPDFObjectHandle oh) @@ -2199,8 +2216,7 @@ QPDF::replaceObject(QPDFObjGen const&amp; og, QPDFObjectHandle oh)
2199 resolve(og); 2216 resolve(og);
2200 2217
2201 // Replace the object in the object cache 2218 // Replace the object in the object cache
2202 - m->obj_cache[og].object->assign(  
2203 - QPDFObjectHandle::ObjAccessor::getObject(oh)); 2219 + updateCache(og, QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1);
2204 } 2220 }
2205 2221
2206 void 2222 void