2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-15 17:17:08 +00:00

Use QPDFObjGen::set in QPDFFormFieldObjectHelper

This commit is contained in:
m-holger 2023-01-05 15:12:31 +00:00
parent d395a90904
commit d60f06c15d

View File

@ -36,20 +36,14 @@ QPDFFormFieldObjectHelper
QPDFFormFieldObjectHelper::getTopLevelField(bool* is_different) QPDFFormFieldObjectHelper::getTopLevelField(bool* is_different)
{ {
auto top_field = this->oh; auto top_field = this->oh;
std::set<QPDFObjGen> seen; QPDFObjGen::set seen;
while (top_field.isDictionary() && while (seen.add(top_field) && !top_field.getKeyIfDict("/Parent").isNull()) {
(!top_field.getKey("/Parent").isNull())) {
top_field = top_field.getKey("/Parent"); top_field = top_field.getKey("/Parent");
if (is_different) { if (is_different) {
*is_different = true; *is_different = true;
} }
auto og = top_field.getObjGen();
if (seen.count(og)) {
break;
}
seen.insert(og);
} }
return QPDFFormFieldObjectHelper(top_field); return {top_field};
} }
QPDFObjectHandle QPDFObjectHandle
@ -76,17 +70,17 @@ QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name)
return QPDFObjectHandle::newNull(); return QPDFObjectHandle::newNull();
} }
QPDFObjectHandle result(node.getKey(name)); QPDFObjectHandle result(node.getKey(name));
std::set<QPDFObjGen> seen; if (result.isNull()) {
while (result.isNull() && node.hasKey("/Parent")) { QPDFObjGen::set seen;
seen.insert(node.getObjGen()); while (seen.add(node) && node.hasKey("/Parent")) {
node = node.getKey("/Parent"); node = node.getKey("/Parent");
if (seen.count(node.getObjGen())) { result = node.getKey(name);
break; if (!result.isNull()) {
} QTC::TC(
result = node.getKey(name); "qpdf",
if (!result.isNull()) { "QPDFFormFieldObjectHelper non-trivial inheritance");
QTC::TC( return result;
"qpdf", "QPDFFormFieldObjectHelper non-trivial inheritance"); }
} }
} }
return result; return result;
@ -127,8 +121,8 @@ QPDFFormFieldObjectHelper::getFullyQualifiedName()
{ {
std::string result; std::string result;
QPDFObjectHandle node = this->oh; QPDFObjectHandle node = this->oh;
std::set<QPDFObjGen> seen; QPDFObjGen::set seen;
while ((!node.isNull()) && (seen.count(node.getObjGen()) == 0)) { while (!node.isNull() && seen.add(node)) {
if (node.getKey("/T").isString()) { if (node.getKey("/T").isString()) {
if (!result.empty()) { if (!result.empty()) {
QTC::TC( QTC::TC(
@ -138,7 +132,6 @@ QPDFFormFieldObjectHelper::getFullyQualifiedName()
} }
result = node.getKey("/T").getUTF8Value() + result; result = node.getKey("/T").getUTF8Value() + result;
} }
seen.insert(node.getObjGen());
node = node.getKey("/Parent"); node = node.getKey("/Parent");
} }
return result; return result;