aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2020-04-02 23:52:21 +0200
committerJay Berkenbilt <ejb@ql.org>2020-04-03 18:16:24 +0200
commit38afdcea7b08226aa6cc12a8fcda93a6f35a0a18 (patch)
tree963a1949e6e28a5f104c6d650f24af56e301ea1e /libqpdf
parent07afb668b14e4b71062b76b1c8fbfb1d88e1d425 (diff)
downloadqpdf-38afdcea7b08226aa6cc12a8fcda93a6f35a0a18.tar.zst
Add QPDFObjectHandle::unsafeShallowCopy
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFObjectHandle.cc37
1 files changed, 28 insertions, 9 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index e7a6223f..4c19b377 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -2461,6 +2461,23 @@ QPDFObjectHandle::hasObjectDescription()
QPDFObjectHandle
QPDFObjectHandle::shallowCopy()
{
+ QPDFObjectHandle result;
+ shallowCopyInternal(result, false);
+ return result;
+}
+
+QPDFObjectHandle
+QPDFObjectHandle::unsafeShallowCopy()
+{
+ QPDFObjectHandle result;
+ shallowCopyInternal(result, true);
+ return result;
+}
+
+void
+QPDFObjectHandle::shallowCopyInternal(QPDFObjectHandle& new_obj,
+ bool first_level_only)
+{
assertInitialized();
if (isStream())
@@ -2470,7 +2487,6 @@ QPDFObjectHandle::shallowCopy()
"attempt to make a shallow copy of a stream");
}
- QPDFObjectHandle new_obj;
if (isArray())
{
QTC::TC("qpdf", "QPDFObjectHandle shallow copy array");
@@ -2491,13 +2507,12 @@ QPDFObjectHandle::shallowCopy()
}
std::set<QPDFObjGen> visited;
- new_obj.copyObject(visited, false);
- return new_obj;
+ new_obj.copyObject(visited, false, first_level_only);
}
void
QPDFObjectHandle::copyObject(std::set<QPDFObjGen>& visited,
- bool cross_indirect)
+ bool cross_indirect, bool first_level_only)
{
assertInitialized();
@@ -2573,9 +2588,11 @@ QPDFObjectHandle::copyObject(std::set<QPDFObjGen>& visited,
for (int i = 0; i < n; ++i)
{
items.push_back(getArrayItem(i));
- if (cross_indirect || (! items.back().isIndirect()))
+ if ((! first_level_only) &&
+ (cross_indirect || (! items.back().isIndirect())))
{
- items.back().copyObject(visited, cross_indirect);
+ items.back().copyObject(
+ visited, cross_indirect, first_level_only);
}
}
new_obj = new QPDF_Array(items);
@@ -2589,9 +2606,11 @@ QPDFObjectHandle::copyObject(std::set<QPDFObjGen>& visited,
iter != keys.end(); ++iter)
{
items[*iter] = getKey(*iter);
- if (cross_indirect || (! items[*iter].isIndirect()))
+ if ((! first_level_only) &&
+ (cross_indirect || (! items[*iter].isIndirect())))
{
- items[*iter].copyObject(visited, cross_indirect);
+ items[*iter].copyObject(
+ visited, cross_indirect, first_level_only);
}
}
new_obj = new QPDF_Dictionary(items);
@@ -2614,7 +2633,7 @@ void
QPDFObjectHandle::makeDirect()
{
std::set<QPDFObjGen> visited;
- copyObject(visited, true);
+ copyObject(visited, true, false);
}
void