From 6caae4d3c6815c5a1e12340734412a3bc7548652 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 5 Jan 2016 16:55:07 -0800 Subject: Replace CPDF_SortObjNumArray with a std::set. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1566553002 . --- core/include/fpdfapi/fpdf_parser.h | 13 ------ .../src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 46 +++++----------------- 2 files changed, 9 insertions(+), 50 deletions(-) (limited to 'core') diff --git a/core/include/fpdfapi/fpdf_parser.h b/core/include/fpdfapi/fpdf_parser.h index bcb35b0ad6..1b1b022fc6 100644 --- a/core/include/fpdfapi/fpdf_parser.h +++ b/core/include/fpdfapi/fpdf_parser.h @@ -915,20 +915,7 @@ class IPDF_DataAvail { IFX_FileAvail* m_pFileAvail; IFX_FileRead* m_pFileRead; }; -class CPDF_SortObjNumArray { - public: - void AddObjNum(FX_DWORD dwObjNum); - - FX_BOOL Find(FX_DWORD dwObjNum); - void RemoveAll() { m_number_array.RemoveAll(); } - - protected: - FX_BOOL BinarySearch(FX_DWORD value, int& iNext); - - protected: - CFX_DWordArray m_number_array; -}; enum PDF_PAGENODE_TYPE { PDF_PAGENODE_UNKOWN = 0, PDF_PAGENODE_PAGE, diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index aaa6fa2f71..5f1aa0b8e4 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -2815,7 +2815,7 @@ class CPDF_DataAvail final : public IPDF_DataAvail { CPDF_Document* m_pDocument; - CPDF_SortObjNumArray m_objnum_array; + std::set m_ObjectSet; CFX_ArrayTemplate m_objs_array; @@ -3057,8 +3057,8 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail( if (!IsDataAvail(offset, size, pHints)) { ret_array.Add(pObj); count++; - } else if (!m_objnum_array.Find(dwNum)) { - m_objnum_array.AddObjNum(dwNum); + } else if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) { + m_ObjectSet.insert(dwNum); CPDF_Object* pReferred = m_pDocument->GetIndirectObject(pRef->GetRefObjNum(), nullptr); if (pReferred) { @@ -3074,7 +3074,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail( CPDF_Object* pObj = new_obj_array[i]; if (CPDF_Reference* pRef = pObj->AsReference()) { FX_DWORD dwNum = pRef->GetRefObjNum(); - if (!m_objnum_array.Find(dwNum)) + if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) ret_array.Add(pObj); } else { ret_array.Add(pObj); @@ -3106,7 +3106,7 @@ IPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) { if (!m_objs_array.GetSize()) { m_objs_array.RemoveAll(); - m_objnum_array.RemoveAll(); + m_ObjectSet.clear(); CFX_ArrayTemplate obj_array; obj_array.Append(m_arrayAcroforms); FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); @@ -4312,7 +4312,7 @@ FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, IFX_DownloadHints* pHints) { if (!m_objs_array.GetSize()) { m_objs_array.RemoveAll(); - m_objnum_array.RemoveAll(); + m_ObjectSet.clear(); CPDF_Dictionary* pPageDict = m_pDocument->GetPage(iPage); if (!pPageDict) { return TRUE; @@ -4382,7 +4382,7 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { m_bAnnotsLoad = FALSE; m_bNeedDownLoadResource = FALSE; m_objs_array.RemoveAll(); - m_objnum_array.RemoveAll(); + m_ObjectSet.clear(); } if (pdfium::ContainsKey(m_pagesLoadState, iPage)) return DataAvailable; @@ -4439,7 +4439,7 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { if (!m_bPageLoadedOK) { if (!m_objs_array.GetSize()) { m_objs_array.RemoveAll(); - m_objnum_array.RemoveAll(); + m_ObjectSet.clear(); m_pPageDict = m_pDocument->GetPage(iPage); if (!m_pPageDict) { ResetFirstCheck(iPage); @@ -4593,35 +4593,7 @@ IPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail( } return FormAvailable; } -void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum) { - int32_t iNext = 0; - if (BinarySearch(dwObjNum, iNext)) { - return; - } - m_number_array.InsertAt(iNext, dwObjNum); -} -FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) { - int32_t iNext = 0; - return BinarySearch(dwObjNum, iNext); -} -FX_BOOL CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t& iNext) { - int32_t iLow = 0; - int32_t iHigh = m_number_array.GetSize() - 1; - while (iLow <= iHigh) { - int32_t iMid = (iLow + iHigh) / 2; - if (m_number_array.GetAt(iMid) == value) { - iNext = iMid; - return TRUE; - } - if (m_number_array.GetAt(iMid) > value) { - iHigh = iMid - 1; - } else if (m_number_array.GetAt(iMid) < value) { - iLow = iMid + 1; - } - } - iNext = iLow; - return FALSE; -} + CPDF_PageNode::~CPDF_PageNode() { for (int32_t i = 0; i < m_childNode.GetSize(); ++i) { delete m_childNode[i]; -- cgit v1.2.3