Skip to content

Commit

Permalink
PdfFilterFactory: Slightly optimized CreateFilterList
Browse files Browse the repository at this point in the history
  • Loading branch information
ceztko committed Nov 5, 2024
1 parent f3ca9c9 commit 058fa79
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/podofo/private/PdfFilterFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,44 +237,41 @@ unique_ptr<InputStream> PdfFilterFactory::CreateDecodeStream(const shared_ptr<In
return std::make_unique<PdfBufferedDecodeStream>(stream, filters, decodeParms);
}

PdfFilterList PdfFilterFactory::CreateFilterList(const PdfObject& filtersObj)
PdfFilterList PdfFilterFactory::CreateFilterList(const PdfObject& filtersObj_)
{
PdfFilterList filters;
const PdfObject* filterKeyObj = nullptr;
if (filtersObj.IsDictionary()
&& (filterKeyObj = filtersObj.GetDictionary().FindKey("Filter")) == nullptr
&& filtersObj.IsArray())
const PdfDictionary* dict;
const PdfName* name;
const PdfArray* arr;
auto filtersObj = &filtersObj_;
if (filtersObj->TryGetDictionary(dict))
{
filterKeyObj = &filtersObj;
}
else if (filtersObj.IsName())
{
filterKeyObj = &filtersObj;
}

if (filterKeyObj == nullptr)
{
// Object had no /Filter key . Return a null filter list.
return filters;
filtersObj = dict->FindKey("Filter");
if (filtersObj == nullptr)
{
// Invalid /Filter key/object. Return a null filter list.
return filters;
}
}

if (filterKeyObj->IsName())
if (filtersObj->TryGetName(name))
{
addFilterTo(filters, filterKeyObj->GetName().GetString());
addFilterTo(filters, name->GetString());
}
else if (filterKeyObj->IsArray())
else if (filtersObj->TryGetArray(arr))
{
for (auto filter : filterKeyObj->GetArray().GetIndirectIterator())
for (auto filter : arr->GetIndirectIterator())
{
if (!filter->IsName())
if (!filter->TryGetName(name))
PODOFO_RAISE_ERROR_INFO(PdfErrorCode::UnsupportedFilter, "Filter array contained unexpected non-name type");

addFilterTo(filters, filter->GetName().GetString());
addFilterTo(filters, name->GetString());
}
}
else
{
PODOFO_RAISE_ERROR_INFO(PdfErrorCode::InvalidDataType, "Unexpected filter container type");
// Invalid /Filter key/object. Return a null filter list.
return filters;
}

return filters;
Expand Down

0 comments on commit 058fa79

Please sign in to comment.