Move some code out of CPDF_NameTree::LookupNamedDest().
Move some of the code into GetNamedDestFromObject(), which will soon be
used in two places, once LookupNamedDest() splits in two. Along the way,
stop declaring variables inside if-statements, and rename variables to
stop using Hungarian notation.
Change-Id: I5eaacc00498363f0c2b867622048ea3caa92e2cc
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/69750
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfdoc/cpdf_nametree.cpp b/core/fpdfdoc/cpdf_nametree.cpp
index 810faf6..0ff847b 100644
--- a/core/fpdfdoc/cpdf_nametree.cpp
+++ b/core/fpdfdoc/cpdf_nametree.cpp
@@ -296,6 +296,18 @@
return nCount;
}
+CPDF_Array* GetNamedDestFromObject(CPDF_Object* obj) {
+ if (!obj)
+ return nullptr;
+ CPDF_Array* array = obj->AsArray();
+ if (array)
+ return array;
+ CPDF_Dictionary* dict = obj->AsDictionary();
+ if (dict)
+ return dict->GetArrayFor("D");
+ return nullptr;
+}
+
} // namespace
CPDF_NameTree::CPDF_NameTree(CPDF_Dictionary* pRoot) : m_pRoot(pRoot) {
@@ -459,11 +471,5 @@
return nullptr;
pValue = pDests->GetDirectObjectFor(name);
}
- if (!pValue)
- return nullptr;
- if (CPDF_Array* pArray = pValue->AsArray())
- return pArray;
- if (CPDF_Dictionary* pDict = pValue->AsDictionary())
- return pDict->GetArrayFor("D");
- return nullptr;
+ return GetNamedDestFromObject(pValue);
}