aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2022-11-14 23:06:04 +0100
committerJay Berkenbilt <jberkenbilt@users.noreply.github.com>2022-11-20 18:07:22 +0100
commit64059014c9288e740214be8242cac4a29e29284c (patch)
treee6faf27f11fbd9d3b37459da0170905bcf7e858f
parentb1eb1a958438025efbf90f7a7f45dbe33c746d91 (diff)
downloadqpdf-64059014c9288e740214be8242cac4a29e29284c.tar.zst
Refactor QPDFObjectHandle::shallowCopy
-rw-r--r--include/qpdf/QPDFObjectHandle.hh2
-rw-r--r--libqpdf/QPDFObjectHandle.cc65
2 files changed, 4 insertions, 63 deletions
diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh
index df6c0742..27b9f9e0 100644
--- a/include/qpdf/QPDFObjectHandle.hh
+++ b/include/qpdf/QPDFObjectHandle.hh
@@ -1628,8 +1628,6 @@ class QPDFObjectHandle
void objectWarning(std::string const& warning);
void assertType(char const* type_name, bool istype);
bool dereference();
- void copyObject1(std::set<QPDFObjGen>& visited);
- void shallowCopyInternal1(QPDFObjectHandle& oh);
void copyObject(
std::set<QPDFObjGen>& visited,
bool cross_indirect,
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 2990b019..6b4d2cd8 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -2200,68 +2200,11 @@ QPDFObjectHandle::hasObjectDescription()
QPDFObjectHandle
QPDFObjectHandle::shallowCopy()
{
- QPDFObjectHandle result;
- shallowCopyInternal1(result);
- return result;
-}
-
-void
-QPDFObjectHandle::shallowCopyInternal1(QPDFObjectHandle& new_obj)
-{
- assertInitialized();
-
- if (isStream()) {
- // Handled bt QPDF_Stream::copy()
- }
- new_obj = QPDFObjectHandle(obj->copy(true));
-
- std::set<QPDFObjGen> visited;
- new_obj.copyObject1(visited);
-}
-
-void
-QPDFObjectHandle::copyObject1(std::set<QPDFObjGen>& visited)
-{
- assertInitialized();
-
- std::shared_ptr<QPDFObject> new_obj;
-
- if (isStream()) {
- new_obj = obj->copy();
- }
-
- auto cur_og = getObjGen();
- if (cur_og.getObj() != 0) {
- if (visited.count(cur_og)) {
- throw std::runtime_error(
- "loop detected while converting object from "
- "indirect to direct");
- }
- visited.insert(cur_og);
- }
-
- if (isReserved()) {
- new_obj = obj->copy();
- }
-
- if (isBool() || isInteger() || isName() || isNull() || isReal() ||
- isString()) {
- // copy(true) and copy(false) are the same
- new_obj = obj->copy();
- } else if (isArray()) {
- new_obj = obj->copy();
- } else if (isDictionary()) {
- new_obj = obj->copy();
- } else {
- throw std::logic_error("QPDFObjectHandle::makeDirectInternal: "
- "unknown object type");
- }
-
- this->obj = new_obj;
-
- if (cur_og.getObj()) {
- visited.erase(cur_og);
+ if (!dereference()) {
+ throw std::logic_error("operation attempted on uninitialized "
+ "QPDFObjectHandle");
}
+ return QPDFObjectHandle(obj->copy());
}
QPDFObjectHandle