Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 1561853002: Merge to XFA: Replace CPDF_SortObjNumArray with a std::set. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/include/fpdfapi/fpdf_parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "parser_int.h" 7 #include "parser_int.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 2797 matching lines...) Expand 10 before | Expand all | Expand 10 after
2808 FX_FILESIZE m_dwTrailerOffset; 2808 FX_FILESIZE m_dwTrailerOffset;
2809 2809
2810 FX_FILESIZE m_dwCurrentOffset; 2810 FX_FILESIZE m_dwCurrentOffset;
2811 2811
2812 PDF_DATAAVAIL_STATUS m_docStatus; 2812 PDF_DATAAVAIL_STATUS m_docStatus;
2813 2813
2814 FX_FILESIZE m_dwFileLen; 2814 FX_FILESIZE m_dwFileLen;
2815 2815
2816 CPDF_Document* m_pDocument; 2816 CPDF_Document* m_pDocument;
2817 2817
2818 CPDF_SortObjNumArray m_objnum_array; 2818 std::set<FX_DWORD> m_ObjectSet;
2819 2819
2820 CFX_ArrayTemplate<CPDF_Object*> m_objs_array; 2820 CFX_ArrayTemplate<CPDF_Object*> m_objs_array;
2821 2821
2822 FX_FILESIZE m_Pos; 2822 FX_FILESIZE m_Pos;
2823 2823
2824 FX_FILESIZE m_bufferOffset; 2824 FX_FILESIZE m_bufferOffset;
2825 2825
2826 FX_DWORD m_bufferSize; 2826 FX_DWORD m_bufferSize;
2827 2827
2828 CFX_ByteString m_WordBuf; 2828 CFX_ByteString m_WordBuf;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
3050 CPDF_Reference* pRef = pObj->AsReference(); 3050 CPDF_Reference* pRef = pObj->AsReference();
3051 FX_DWORD dwNum = pRef->GetRefObjNum(); 3051 FX_DWORD dwNum = pRef->GetRefObjNum();
3052 FX_FILESIZE offset; 3052 FX_FILESIZE offset;
3053 FX_DWORD size = GetObjectSize(dwNum, offset); 3053 FX_DWORD size = GetObjectSize(dwNum, offset);
3054 if (size == 0 || offset < 0 || offset >= m_dwFileLen) { 3054 if (size == 0 || offset < 0 || offset >= m_dwFileLen) {
3055 break; 3055 break;
3056 } 3056 }
3057 if (!IsDataAvail(offset, size, pHints)) { 3057 if (!IsDataAvail(offset, size, pHints)) {
3058 ret_array.Add(pObj); 3058 ret_array.Add(pObj);
3059 count++; 3059 count++;
3060 } else if (!m_objnum_array.Find(dwNum)) { 3060 } else if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) {
3061 m_objnum_array.AddObjNum(dwNum); 3061 m_ObjectSet.insert(dwNum);
3062 CPDF_Object* pReferred = 3062 CPDF_Object* pReferred =
3063 m_pDocument->GetIndirectObject(pRef->GetRefObjNum(), nullptr); 3063 m_pDocument->GetIndirectObject(pRef->GetRefObjNum(), nullptr);
3064 if (pReferred) { 3064 if (pReferred) {
3065 new_obj_array.Add(pReferred); 3065 new_obj_array.Add(pReferred);
3066 } 3066 }
3067 } 3067 }
3068 } break; 3068 } break;
3069 } 3069 }
3070 } 3070 }
3071 if (count > 0) { 3071 if (count > 0) {
3072 int32_t iSize = new_obj_array.GetSize(); 3072 int32_t iSize = new_obj_array.GetSize();
3073 for (i = 0; i < iSize; ++i) { 3073 for (i = 0; i < iSize; ++i) {
3074 CPDF_Object* pObj = new_obj_array[i]; 3074 CPDF_Object* pObj = new_obj_array[i];
3075 if (CPDF_Reference* pRef = pObj->AsReference()) { 3075 if (CPDF_Reference* pRef = pObj->AsReference()) {
3076 FX_DWORD dwNum = pRef->GetRefObjNum(); 3076 FX_DWORD dwNum = pRef->GetRefObjNum();
3077 if (!m_objnum_array.Find(dwNum)) 3077 if (!pdfium::ContainsKey(m_ObjectSet, dwNum))
3078 ret_array.Add(pObj); 3078 ret_array.Add(pObj);
3079 } else { 3079 } else {
3080 ret_array.Add(pObj); 3080 ret_array.Add(pObj);
3081 } 3081 }
3082 } 3082 }
3083 return FALSE; 3083 return FALSE;
3084 } 3084 }
3085 obj_array.RemoveAll(); 3085 obj_array.RemoveAll();
3086 obj_array.Append(new_obj_array); 3086 obj_array.Append(new_obj_array);
3087 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array); 3087 return IsObjectsAvail(obj_array, FALSE, pHints, ret_array);
(...skipping 11 matching lines...) Expand all
3099 if (!CheckDocStatus(pHints)) { 3099 if (!CheckDocStatus(pHints)) {
3100 return DataNotAvailable; 3100 return DataNotAvailable;
3101 } 3101 }
3102 } 3102 }
3103 return DataAvailable; 3103 return DataAvailable;
3104 } 3104 }
3105 3105
3106 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) { 3106 FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) {
3107 if (!m_objs_array.GetSize()) { 3107 if (!m_objs_array.GetSize()) {
3108 m_objs_array.RemoveAll(); 3108 m_objs_array.RemoveAll();
3109 m_objnum_array.RemoveAll(); 3109 m_ObjectSet.clear();
3110 CFX_ArrayTemplate<CPDF_Object*> obj_array; 3110 CFX_ArrayTemplate<CPDF_Object*> obj_array;
3111 obj_array.Append(m_arrayAcroforms); 3111 obj_array.Append(m_arrayAcroforms);
3112 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array); 3112 FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array);
3113 if (bRet) { 3113 if (bRet) {
3114 m_objs_array.RemoveAll(); 3114 m_objs_array.RemoveAll();
3115 } 3115 }
3116 return bRet; 3116 return bRet;
3117 } 3117 }
3118 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; 3118 CFX_ArrayTemplate<CPDF_Object*> new_objs_array;
3119 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); 3119 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
4305 m_bMainXRefLoadedOK = TRUE; 4305 m_bMainXRefLoadedOK = TRUE;
4306 m_bLinearedDataOK = TRUE; 4306 m_bLinearedDataOK = TRUE;
4307 } 4307 }
4308 4308
4309 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable; 4309 return m_bLinearedDataOK ? DataAvailable : DataNotAvailable;
4310 } 4310 }
4311 FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage, 4311 FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage,
4312 IFX_DownloadHints* pHints) { 4312 IFX_DownloadHints* pHints) {
4313 if (!m_objs_array.GetSize()) { 4313 if (!m_objs_array.GetSize()) {
4314 m_objs_array.RemoveAll(); 4314 m_objs_array.RemoveAll();
4315 m_objnum_array.RemoveAll(); 4315 m_ObjectSet.clear();
4316 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(iPage); 4316 CPDF_Dictionary* pPageDict = m_pDocument->GetPage(iPage);
4317 if (!pPageDict) { 4317 if (!pPageDict) {
4318 return TRUE; 4318 return TRUE;
4319 } 4319 }
4320 CPDF_Object* pAnnots = pPageDict->GetElement("Annots"); 4320 CPDF_Object* pAnnots = pPageDict->GetElement("Annots");
4321 if (!pAnnots) { 4321 if (!pAnnots) {
4322 return TRUE; 4322 return TRUE;
4323 } 4323 }
4324 CFX_ArrayTemplate<CPDF_Object*> obj_array; 4324 CFX_ArrayTemplate<CPDF_Object*> obj_array;
4325 obj_array.Add(pAnnots); 4325 obj_array.Add(pAnnots);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
4375 int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { 4375 int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
4376 if (!m_pDocument) { 4376 if (!m_pDocument) {
4377 return DataError; 4377 return DataError;
4378 } 4378 }
4379 if (IsFirstCheck(iPage)) { 4379 if (IsFirstCheck(iPage)) {
4380 m_bCurPageDictLoadOK = FALSE; 4380 m_bCurPageDictLoadOK = FALSE;
4381 m_bPageLoadedOK = FALSE; 4381 m_bPageLoadedOK = FALSE;
4382 m_bAnnotsLoad = FALSE; 4382 m_bAnnotsLoad = FALSE;
4383 m_bNeedDownLoadResource = FALSE; 4383 m_bNeedDownLoadResource = FALSE;
4384 m_objs_array.RemoveAll(); 4384 m_objs_array.RemoveAll();
4385 m_objnum_array.RemoveAll(); 4385 m_ObjectSet.clear();
4386 } 4386 }
4387 if (pdfium::ContainsKey(m_pagesLoadState, iPage)) 4387 if (pdfium::ContainsKey(m_pagesLoadState, iPage))
4388 return DataAvailable; 4388 return DataAvailable;
4389 4389
4390 if (m_bLinearized) { 4390 if (m_bLinearized) {
4391 if ((FX_DWORD)iPage == m_dwFirstPageNo) { 4391 if ((FX_DWORD)iPage == m_dwFirstPageNo) {
4392 if (!CheckLinearizedFirstPage(iPage, pHints)) 4392 if (!CheckLinearizedFirstPage(iPage, pHints))
4393 return DataNotAvailable; 4393 return DataNotAvailable;
4394 m_pagesLoadState.insert(iPage); 4394 m_pagesLoadState.insert(iPage);
4395 return DataAvailable; 4395 return DataAvailable;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4432 } 4432 }
4433 if (m_bHaveAcroForm && !m_bAcroFormLoad) { 4433 if (m_bHaveAcroForm && !m_bAcroFormLoad) {
4434 if (!CheckAcroFormSubObject(pHints)) { 4434 if (!CheckAcroFormSubObject(pHints)) {
4435 return DataNotAvailable; 4435 return DataNotAvailable;
4436 } 4436 }
4437 m_bAcroFormLoad = TRUE; 4437 m_bAcroFormLoad = TRUE;
4438 } 4438 }
4439 if (!m_bPageLoadedOK) { 4439 if (!m_bPageLoadedOK) {
4440 if (!m_objs_array.GetSize()) { 4440 if (!m_objs_array.GetSize()) {
4441 m_objs_array.RemoveAll(); 4441 m_objs_array.RemoveAll();
4442 m_objnum_array.RemoveAll(); 4442 m_ObjectSet.clear();
4443 m_pPageDict = m_pDocument->GetPage(iPage); 4443 m_pPageDict = m_pDocument->GetPage(iPage);
4444 if (!m_pPageDict) { 4444 if (!m_pPageDict) {
4445 ResetFirstCheck(iPage); 4445 ResetFirstCheck(iPage);
4446 return DataAvailable; 4446 return DataAvailable;
4447 } 4447 }
4448 CFX_ArrayTemplate<CPDF_Object*> obj_array; 4448 CFX_ArrayTemplate<CPDF_Object*> obj_array;
4449 obj_array.Add(m_pPageDict); 4449 obj_array.Add(m_pPageDict);
4450 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array); 4450 FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array);
4451 if (bRet) { 4451 if (bRet) {
4452 m_objs_array.RemoveAll(); 4452 m_objs_array.RemoveAll();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
4586 } 4586 }
4587 CFX_ArrayTemplate<CPDF_Object*> new_objs_array; 4587 CFX_ArrayTemplate<CPDF_Object*> new_objs_array;
4588 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array); 4588 FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
4589 m_objs_array.RemoveAll(); 4589 m_objs_array.RemoveAll();
4590 if (!bRet) { 4590 if (!bRet) {
4591 m_objs_array.Append(new_objs_array); 4591 m_objs_array.Append(new_objs_array);
4592 return FormNotAvailable; 4592 return FormNotAvailable;
4593 } 4593 }
4594 return FormAvailable; 4594 return FormAvailable;
4595 } 4595 }
4596 void CPDF_SortObjNumArray::AddObjNum(FX_DWORD dwObjNum) { 4596
4597 int32_t iNext = 0;
4598 if (BinarySearch(dwObjNum, iNext)) {
4599 return;
4600 }
4601 m_number_array.InsertAt(iNext, dwObjNum);
4602 }
4603 FX_BOOL CPDF_SortObjNumArray::Find(FX_DWORD dwObjNum) {
4604 int32_t iNext = 0;
4605 return BinarySearch(dwObjNum, iNext);
4606 }
4607 FX_BOOL CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t& iNext) {
4608 int32_t iLow = 0;
4609 int32_t iHigh = m_number_array.GetSize() - 1;
4610 while (iLow <= iHigh) {
4611 int32_t iMid = (iLow + iHigh) / 2;
4612 if (m_number_array.GetAt(iMid) == value) {
4613 iNext = iMid;
4614 return TRUE;
4615 }
4616 if (m_number_array.GetAt(iMid) > value) {
4617 iHigh = iMid - 1;
4618 } else if (m_number_array.GetAt(iMid) < value) {
4619 iLow = iMid + 1;
4620 }
4621 }
4622 iNext = iLow;
4623 return FALSE;
4624 }
4625 CPDF_PageNode::~CPDF_PageNode() { 4597 CPDF_PageNode::~CPDF_PageNode() {
4626 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) { 4598 for (int32_t i = 0; i < m_childNode.GetSize(); ++i) {
4627 delete m_childNode[i]; 4599 delete m_childNode[i];
4628 } 4600 }
4629 m_childNode.RemoveAll(); 4601 m_childNode.RemoveAll();
4630 } 4602 }
4631 CPDF_HintTables::~CPDF_HintTables() { 4603 CPDF_HintTables::~CPDF_HintTables() {
4632 m_dwDeltaNObjsArray.RemoveAll(); 4604 m_dwDeltaNObjsArray.RemoveAll();
4633 m_dwNSharedObjsArray.RemoveAll(); 4605 m_dwNSharedObjsArray.RemoveAll();
4634 m_dwSharedObjNumArray.RemoveAll(); 4606 m_dwSharedObjNumArray.RemoveAll();
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
4995 if (!m_pLinearizedDict) 4967 if (!m_pLinearizedDict)
4996 return -1; 4968 return -1;
4997 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); 4969 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H");
4998 if (!pRange) 4970 if (!pRange)
4999 return -1; 4971 return -1;
5000 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 4972 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
5001 if (!pStreamLen) 4973 if (!pStreamLen)
5002 return -1; 4974 return -1;
5003 return pStreamLen->GetInteger(); 4975 return pStreamLen->GetInteger();
5004 } 4976 }
OLDNEW
« no previous file with comments | « core/include/fpdfapi/fpdf_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698