diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-08-18 09:20:29 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-08-18 09:20:29 -0700 |
commit | 85d5c4af4a9546970b34dd413c473d10fef8534b (patch) | |
tree | b993a0309a69b5c31c122971be04d062e3ae341c /core/src/fpdfapi/fpdf_parser | |
parent | 57207efd5f17ec63e174061ea5415afb58516fce (diff) | |
download | pdfium-85d5c4af4a9546970b34dd413c473d10fef8534b.tar.xz |
FX_CMapDwordToDword considered harmful.
Lookups are log(n), but random insertions could result in n^2
behaviour. Replace with maps and sets.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1289703003 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 43 |
1 files changed, 10 insertions, 33 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index a12a2894a5..4f81be1d3f 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -4,6 +4,7 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include <set> #include <utility> #include <vector> @@ -3003,9 +3004,8 @@ class CPDF_DataAvail final : public IPDF_DataAvail { CPDF_PageNode m_pageNodes; - CFX_CMapDWordToDWord* m_pageMapCheckState; - - CFX_CMapDWordToDWord* m_pagesLoadState; + std::set<FX_DWORD> m_pageMapCheckState; + std::set<FX_DWORD> m_pagesLoadState; }; IPDF_DataAvail::IPDF_DataAvail(IFX_FileAvail* pFileAvail, @@ -3063,13 +3063,11 @@ CPDF_DataAvail::CPDF_DataAvail(IFX_FileAvail* pFileAvail, m_pAcroForm = NULL; m_pPageDict = NULL; m_pPageResource = NULL; - m_pageMapCheckState = NULL; m_docStatus = PDF_DATAAVAIL_HEADER; m_parser.m_bOwnFileRead = FALSE; m_bTotalLoadPageTree = FALSE; m_bCurPageDictLoadOK = FALSE; m_bLinearedDataOK = FALSE; - m_pagesLoadState = NULL; } CPDF_DataAvail::~CPDF_DataAvail() { if (m_pLinearized) { @@ -3081,8 +3079,6 @@ CPDF_DataAvail::~CPDF_DataAvail() { if (m_pTrailer) { m_pTrailer->Release(); } - delete m_pageMapCheckState; - delete m_pagesLoadState; int32_t i = 0; int32_t iSize = m_arrayAcroforms.GetSize(); for (i = 0; i < iSize; ++i) { @@ -3517,29 +3513,14 @@ FX_BOOL CPDF_DataAvail::PreparePageItem() { return TRUE; } FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) { - if (NULL == m_pageMapCheckState) { - m_pageMapCheckState = new CFX_CMapDWordToDWord(); - } - FX_DWORD dwValue = 0; - if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { - m_pageMapCheckState->SetAt(iPage, 1); - return TRUE; - } - if (dwValue != 0) { + if (m_pageMapCheckState.find(iPage) != m_pageMapCheckState.end()) return FALSE; - } - m_pageMapCheckState->SetAt(iPage, 1); + + m_pageMapCheckState.insert(iPage); return TRUE; } void CPDF_DataAvail::ResetFirstCheck(int iPage) { - if (NULL == m_pageMapCheckState) { - m_pageMapCheckState = new CFX_CMapDWordToDWord(); - } - FX_DWORD dwValue = 1; - if (!m_pageMapCheckState->Lookup(iPage, dwValue)) { - return; - } - m_pageMapCheckState->SetAt(iPage, 0); + m_pageMapCheckState.erase(iPage); } FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) { FX_DWORD iPageObjs = m_PageObjList.GetSize(); @@ -4513,16 +4494,12 @@ FX_BOOL CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { m_objs_array.RemoveAll(); m_objnum_array.RemoveAll(); } - if (m_pagesLoadState == NULL) { - m_pagesLoadState = new CFX_CMapDWordToDWord(); - } - FX_DWORD dwPageLoad = 0; - if (m_pagesLoadState->Lookup(iPage, dwPageLoad) && dwPageLoad != 0) { + if (m_pagesLoadState.find(iPage) != m_pagesLoadState.end()) { return TRUE; } if (m_bLinearized) { if ((FX_DWORD)iPage == m_dwFirstPageNo) { - m_pagesLoadState->SetAt(iPage, TRUE); + m_pagesLoadState.insert(iPage); return TRUE; } if (!CheckLinearizedData(pHints)) { @@ -4617,7 +4594,7 @@ FX_BOOL CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { m_bAnnotsLoad = FALSE; m_bCurPageDictLoadOK = FALSE; ResetFirstCheck(iPage); - m_pagesLoadState->SetAt(iPage, TRUE); + m_pagesLoadState.insert(iPage); return TRUE; } FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) { |