Remove unnecessary ToArray() calls and locals in CPDF_Dest. Rename GetObject() to GetArray() and remove more ToArray() calls. Change-Id: I754ca72b32c085e1801d3cedcd291ce4d2682359 Reviewed-on: https://pdfium-review.googlesource.com/41353 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfdoc/cpdf_dest.cpp b/core/fpdfdoc/cpdf_dest.cpp index 8dd58b1..308336e 100644 --- a/core/fpdfdoc/cpdf_dest.cpp +++ b/core/fpdfdoc/cpdf_dest.cpp
@@ -34,16 +34,15 @@ CPDF_Dest::CPDF_Dest(const CPDF_Dest& that) = default; -CPDF_Dest::CPDF_Dest(const CPDF_Array* pObj) : m_pObj(pObj) {} +CPDF_Dest::CPDF_Dest(const CPDF_Array* pArray) : m_pArray(pArray) {} CPDF_Dest::~CPDF_Dest() {} int CPDF_Dest::GetDestPageIndex(CPDF_Document* pDoc) const { - const CPDF_Array* pArray = ToArray(m_pObj.Get()); - if (!pArray) + if (!m_pArray) return -1; - const CPDF_Object* pPage = pArray->GetDirectObjectAt(0); + const CPDF_Object* pPage = m_pArray->GetDirectObjectAt(0); if (!pPage) return -1; @@ -57,11 +56,10 @@ } uint32_t CPDF_Dest::GetPageObjNum() const { - const CPDF_Array* pArray = ToArray(m_pObj.Get()); - if (!pArray) + if (!m_pArray) return 0; - const CPDF_Object* pPage = pArray->GetDirectObjectAt(0); + const CPDF_Object* pPage = m_pArray->GetDirectObjectAt(0); if (!pPage) return 0; if (pPage->IsNumber()) @@ -72,15 +70,14 @@ } int CPDF_Dest::GetZoomMode() const { - const CPDF_Array* pArray = ToArray(m_pObj.Get()); + if (!m_pArray) + return 0; + + const CPDF_Object* pArray = m_pArray->GetDirectObjectAt(1); if (!pArray) return 0; - const CPDF_Object* pObj = pArray->GetDirectObjectAt(1); - if (!pObj) - return 0; - - ByteString mode = pObj->GetString(); + ByteString mode = pArray->GetString(); for (int i = 1; g_sZoomModes[i]; ++i) { if (mode == g_sZoomModes[i]) return i; @@ -99,20 +96,19 @@ *pHasY = false; *pHasZoom = false; - const CPDF_Array* pArray = ToArray(m_pObj.Get()); - if (!pArray) + if (!m_pArray) return false; - if (pArray->GetCount() < 5) + if (m_pArray->GetCount() < 5) return false; - const CPDF_Name* xyz = ToName(pArray->GetDirectObjectAt(1)); + const CPDF_Name* xyz = ToName(m_pArray->GetDirectObjectAt(1)); if (!xyz || xyz->GetString() != "XYZ") return false; - const CPDF_Number* numX = ToNumber(pArray->GetDirectObjectAt(2)); - const CPDF_Number* numY = ToNumber(pArray->GetDirectObjectAt(3)); - const CPDF_Number* numZoom = ToNumber(pArray->GetDirectObjectAt(4)); + const CPDF_Number* numX = ToNumber(m_pArray->GetDirectObjectAt(2)); + const CPDF_Number* numY = ToNumber(m_pArray->GetDirectObjectAt(3)); + const CPDF_Number* numZoom = ToNumber(m_pArray->GetDirectObjectAt(4)); // If the value is a CPDF_Null then ToNumber will return nullptr. *pHasX = !!numX; @@ -137,20 +133,18 @@ } unsigned long CPDF_Dest::GetNumParams() const { - const CPDF_Array* pArray = ToArray(m_pObj.Get()); - if (!pArray || pArray->GetCount() < 2) + if (!m_pArray || m_pArray->GetCount() < 2) return 0; unsigned long maxParamsForFitType = g_sZoomModeMaxParamCount[GetZoomMode()]; - unsigned long numParamsInArray = pArray->GetCount() - 2; + unsigned long numParamsInArray = m_pArray->GetCount() - 2; return std::min(maxParamsForFitType, numParamsInArray); } float CPDF_Dest::GetParam(int index) const { - const CPDF_Array* pArray = ToArray(m_pObj.Get()); - return pArray ? pArray->GetNumberAt(2 + index) : 0; + return m_pArray ? m_pArray->GetNumberAt(2 + index) : 0; } ByteString CPDF_Dest::GetRemoteName() const { - return m_pObj ? m_pObj->GetString() : ByteString(); + return m_pArray ? m_pArray->GetString() : ByteString(); }
diff --git a/core/fpdfdoc/cpdf_dest.h b/core/fpdfdoc/cpdf_dest.h index c30db11..ff8458d 100644 --- a/core/fpdfdoc/cpdf_dest.h +++ b/core/fpdfdoc/cpdf_dest.h
@@ -18,10 +18,10 @@ public: CPDF_Dest(); CPDF_Dest(const CPDF_Dest& that); - explicit CPDF_Dest(const CPDF_Array* pObj); + explicit CPDF_Dest(const CPDF_Array* pArray); ~CPDF_Dest(); - const CPDF_Array* GetObject() const { return m_pObj.Get(); } + const CPDF_Array* GetArray() const { return m_pArray.Get(); } ByteString GetRemoteName() const; int GetDestPageIndex(CPDF_Document* pDoc) const; @@ -41,7 +41,7 @@ float* pZoom) const; private: - UnownedPtr<const CPDF_Array> const m_pObj; + UnownedPtr<const CPDF_Array> const m_pArray; }; #endif // CORE_FPDFDOC_CPDF_DEST_H_
diff --git a/fpdfsdk/cpdfsdk_actionhandler.cpp b/fpdfsdk/cpdfsdk_actionhandler.cpp index 64d82b9..f951bfb 100644 --- a/fpdfsdk/cpdfsdk_actionhandler.cpp +++ b/fpdfsdk/cpdfsdk_actionhandler.cpp
@@ -364,7 +364,7 @@ CPDF_Dest MyDest = action.GetDest(pPDFDocument); int nPageIndex = MyDest.GetDestPageIndex(pPDFDocument); int nFitType = MyDest.GetZoomMode(); - const CPDF_Array* pMyArray = ToArray(MyDest.GetObject()); + const CPDF_Array* pMyArray = MyDest.GetArray(); std::vector<float> posArray; if (pMyArray) { for (size_t i = 2; i < pMyArray->GetCount(); i++)
diff --git a/fpdfsdk/fpdf_doc.cpp b/fpdfsdk/fpdf_doc.cpp index 1f0d4f2..d3c8e23 100644 --- a/fpdfsdk/fpdf_doc.cpp +++ b/fpdfsdk/fpdf_doc.cpp
@@ -121,14 +121,14 @@ return nullptr; CPDF_Bookmark bookmark(CPDFDictionaryFromFPDFBookmark(pDict)); CPDF_Dest dest = bookmark.GetDest(pDoc); - if (dest.GetObject()) - return FPDFDestFromCPDFArray(dest.GetObject()); + if (dest.GetArray()) + return FPDFDestFromCPDFArray(dest.GetArray()); // If this bookmark is not directly associated with a dest, we try to get // action CPDF_Action action = bookmark.GetAction(); if (!action.GetDict()) return nullptr; - return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetObject()); + return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetArray()); } FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV @@ -167,7 +167,7 @@ if (!pDoc) return nullptr; CPDF_Action action(CPDFDictionaryFromFPDFAction(pDict)); - return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetObject()); + return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetArray()); } FPDF_EXPORT unsigned long FPDF_CALLCONV @@ -302,14 +302,14 @@ if (!pDoc) return nullptr; CPDF_Link link(CPDFDictionaryFromFPDFLink(pDict)); - FPDF_DEST dest = FPDFDestFromCPDFArray(link.GetDest(pDoc).GetObject()); + FPDF_DEST dest = FPDFDestFromCPDFArray(link.GetDest(pDoc).GetArray()); if (dest) return dest; // If this link is not directly associated with a dest, we try to get action CPDF_Action action = link.GetAction(); if (!action.GetDict()) return nullptr; - return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetObject()); + return FPDFDestFromCPDFArray(action.GetDest(pDoc).GetArray()); } FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFLink_GetAction(FPDF_LINK pDict) {
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp index 486da11..c839e9f 100644 --- a/fxjs/cjs_document.cpp +++ b/fxjs/cjs_document.cpp
@@ -1458,7 +1458,7 @@ return CJS_Result::Failure(JSMessage::kBadObjectError); CPDF_Dest dest(destArray); - const CPDF_Array* arrayObject = ToArray(dest.GetObject()); + const CPDF_Array* arrayObject = dest.GetArray(); std::vector<float> scrollPositionArray; if (arrayObject) { for (size_t i = 2; i < arrayObject->GetCount(); i++)