2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

Remove redundant QPDFObjectHandle::copyObject2

copyObject2 repeats a second time what
new_obj = QPDFObjectHandle(obj->copy(true))
in shallowCopyInternal2 already did.
This commit is contained in:
m-holger 2022-11-20 13:56:03 +00:00 committed by Jay Berkenbilt
parent 15e8d3a763
commit 0289b21c3b
2 changed files with 0 additions and 65 deletions

View File

@ -1634,7 +1634,6 @@ class QPDFObjectHandle
bool first_level_only,
bool stop_at_streams);
void shallowCopyInternal1(QPDFObjectHandle& oh, bool first_level_only);
void copyObject2(std::set<QPDFObjGen>& visited);
void shallowCopyInternal2(QPDFObjectHandle& oh);
void copyObject(
std::set<QPDFObjGen>& visited,

View File

@ -2312,70 +2312,6 @@ QPDFObjectHandle::shallowCopyInternal2(QPDFObjectHandle& new_obj)
throw std::runtime_error("attempt to make a shallow copy of a stream");
}
new_obj = QPDFObjectHandle(obj->copy(true));
std::set<QPDFObjGen> visited;
new_obj.copyObject2(visited);
}
void
QPDFObjectHandle::copyObject2(std::set<QPDFObjGen>& visited)
{
assertInitialized();
if (isStream()) {
// same as obj->copy(true)
throw std::runtime_error(
"attempt to make a stream into a direct object");
}
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()) {
// same as obj->copy(true)
throw std::logic_error("QPDFObjectHandle: attempting to make a"
" reserved object handle direct");
}
std::shared_ptr<QPDFObject> new_obj;
if (isBool() || isInteger() || isName() || isNull() || isReal() ||
isString()) {
new_obj = obj->copy(true);
} else if (isArray()) {
// same as obj->copy(true)
std::vector<QPDFObjectHandle> items;
auto array = asArray();
int n = array->getNItems();
for (int i = 0; i < n; ++i) {
items.push_back(array->getItem(i));
}
new_obj = QPDF_Array::create(items);
} else if (isDictionary()) {
// same as obj->copy(true)
std::map<std::string, QPDFObjectHandle> items;
auto dict = asDictionary();
for (auto const& key: getKeys()) {
items[key] = dict->getKey(key);
}
new_obj = QPDF_Dictionary::create(items);
} else {
throw std::logic_error("QPDFObjectHandle::makeDirectInternal: "
"unknown object type");
}
this->obj = new_obj;
if (cur_og.getObj()) {
visited.erase(cur_og);
}
}
void