Commit 27fae2b55e835a41277df78f090d4baf6fe05c1e
1 parent
431bd666
Remove QPDF::ObjectChanged
Also change QPDF::replaceObject and QPDF::swapObjects such that the QPDFObject assigned to an og in the obj_cache is never replaced; only QPDFObject::value is updated.
Showing
3 changed files
with
4 additions
and
42 deletions
include/qpdf/QPDF.hh
| ... | ... | @@ -851,12 +851,6 @@ class QPDF |
| 851 | 851 | { |
| 852 | 852 | return qpdf->resolve(og); |
| 853 | 853 | } |
| 854 | - static bool | |
| 855 | - objectChanged( | |
| 856 | - QPDF* qpdf, QPDFObjGen const& og, std::shared_ptr<QPDFObject>& oph) | |
| 857 | - { | |
| 858 | - return qpdf->objectChanged(og, oph); | |
| 859 | - } | |
| 860 | 854 | }; |
| 861 | 855 | friend class Resolver; |
| 862 | 856 | |
| ... | ... | @@ -1174,7 +1168,6 @@ class QPDF |
| 1174 | 1168 | std::string const& description, |
| 1175 | 1169 | QPDFObjGen const& exp_og, |
| 1176 | 1170 | QPDFObjGen& og); |
| 1177 | - bool objectChanged(QPDFObjGen const& og, std::shared_ptr<QPDFObject>& oph); | |
| 1178 | 1171 | std::shared_ptr<QPDFObject> resolve(QPDFObjGen const& og); |
| 1179 | 1172 | void resolveObjectsInStream(int obj_stream_number); |
| 1180 | 1173 | void stopOnError(std::string const& message); |
| ... | ... | @@ -1729,7 +1722,6 @@ class QPDF |
| 1729 | 1722 | bool in_parse; |
| 1730 | 1723 | bool parsed; |
| 1731 | 1724 | std::set<int> resolved_object_streams; |
| 1732 | - bool ever_replaced_objects; | |
| 1733 | 1725 | |
| 1734 | 1726 | // Linearization data |
| 1735 | 1727 | qpdf_offset_t first_xref_item_offset; // actual value from file | ... | ... |
libqpdf/QPDF.cc
| ... | ... | @@ -223,7 +223,6 @@ QPDF::Members::Members() : |
| 223 | 223 | immediate_copy_from(false), |
| 224 | 224 | in_parse(false), |
| 225 | 225 | parsed(false), |
| 226 | - ever_replaced_objects(false), | |
| 227 | 226 | first_xref_item_offset(0), |
| 228 | 227 | uncompressed_after_compressed(false) |
| 229 | 228 | { |
| ... | ... | @@ -1928,28 +1927,6 @@ QPDF::readObjectAtOffset( |
| 1928 | 1927 | return oh; |
| 1929 | 1928 | } |
| 1930 | 1929 | |
| 1931 | -bool | |
| 1932 | -QPDF::objectChanged(QPDFObjGen const& og, std::shared_ptr<QPDFObject>& oph) | |
| 1933 | -{ | |
| 1934 | - // See if the object cached at og, if any, is the one passed in. | |
| 1935 | - // QPDFObjectHandle uses this to detect outdated handles to | |
| 1936 | - // replaced or swapped objects. This is a somewhat expensive check | |
| 1937 | - // because it happens with every dereference of a | |
| 1938 | - // QPDFObjectHandle. To reduce the hit somewhat, short-circuit the | |
| 1939 | - // check if we never called a function that replaces an object | |
| 1940 | - // already in cache. It is important for functions that do this to | |
| 1941 | - // set ever_replaced_objects = true. | |
| 1942 | - | |
| 1943 | - if (!this->m->ever_replaced_objects) { | |
| 1944 | - return false; | |
| 1945 | - } | |
| 1946 | - auto c = this->m->obj_cache.find(og); | |
| 1947 | - if (c == this->m->obj_cache.end()) { | |
| 1948 | - return true; | |
| 1949 | - } | |
| 1950 | - return (c->second.object.get() != oph.get()); | |
| 1951 | -} | |
| 1952 | - | |
| 1953 | 1930 | std::shared_ptr<QPDFObject> |
| 1954 | 1931 | QPDF::resolve(QPDFObjGen const& og) |
| 1955 | 1932 | { |
| ... | ... | @@ -2207,14 +2184,12 @@ QPDF::replaceObject(QPDFObjGen const& og, QPDFObjectHandle oh) |
| 2207 | 2184 | throw std::logic_error( |
| 2208 | 2185 | "QPDF::replaceObject called with indirect object handle"); |
| 2209 | 2186 | } |
| 2210 | - | |
| 2211 | 2187 | // Force new object to appear in the cache |
| 2212 | 2188 | resolve(og); |
| 2213 | 2189 | |
| 2214 | 2190 | // Replace the object in the object cache |
| 2215 | - this->m->ever_replaced_objects = true; | |
| 2216 | - this->m->obj_cache[og] = | |
| 2217 | - ObjCache(QPDFObjectHandle::ObjAccessor::getObject(oh), -1, -1); | |
| 2191 | + m->obj_cache[og].object->assign( | |
| 2192 | + QPDFObjectHandle::ObjAccessor::getObject(oh)); | |
| 2218 | 2193 | } |
| 2219 | 2194 | |
| 2220 | 2195 | void |
| ... | ... | @@ -2536,10 +2511,7 @@ QPDF::swapObjects(QPDFObjGen const& og1, QPDFObjGen const& og2) |
| 2536 | 2511 | // cache. |
| 2537 | 2512 | resolve(og1); |
| 2538 | 2513 | resolve(og2); |
| 2539 | - ObjCache t = this->m->obj_cache[og1]; | |
| 2540 | - this->m->ever_replaced_objects = true; | |
| 2541 | - this->m->obj_cache[og1] = this->m->obj_cache[og2]; | |
| 2542 | - this->m->obj_cache[og2] = t; | |
| 2514 | + m->obj_cache[og1].object->swapWith(m->obj_cache[og2].object); | |
| 2543 | 2515 | } |
| 2544 | 2516 | |
| 2545 | 2517 | unsigned long long | ... | ... |
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -2611,9 +2611,7 @@ QPDFObjectHandle::dereference() |
| 2611 | 2611 | if (!this->initialized) { |
| 2612 | 2612 | return false; |
| 2613 | 2613 | } |
| 2614 | - if ((this->obj->getTypeCode() == QPDFObject::ot_unresolved) || | |
| 2615 | - (getObjectID() && | |
| 2616 | - QPDF::Resolver::objectChanged(this->qpdf, getObjGen(), this->obj))) { | |
| 2614 | + if (this->obj->getTypeCode() == QPDFObject::ot_unresolved) { | |
| 2617 | 2615 | this->obj = QPDF::Resolver::resolve(this->qpdf, getObjGen()); |
| 2618 | 2616 | } |
| 2619 | 2617 | return true; | ... | ... |