diff options
author | Lei Zhang <thestig@chromium.org> | 2015-12-22 13:49:44 -0800 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-12-22 13:49:44 -0800 |
commit | cd2bb30aba89a05c0bbd4d6973fa070205e3a1e8 (patch) | |
tree | 0eca7841e7be4b9392bbcd0ffb656a8495f64792 /core/src/fpdfapi/fpdf_parser | |
parent | bc75f1737f7eb8d45c5a2ebd3ad78203782c1642 (diff) | |
download | pdfium-cd2bb30aba89a05c0bbd4d6973fa070205e3a1e8.tar.xz |
Merge to XFA: Add ContainsKey() and ContainsValue() and use them where appropriate.
TBR=ochang@chromium.org
Review URL: https://codereview.chromium.org/1540263003 .
(cherry picked from commit 1fc92867ca53f0fba4272fbee3814d844f487495)
Review URL: https://codereview.chromium.org/1542193002 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 9 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 20 |
2 files changed, 12 insertions, 17 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index 1322864757..b94a6d91b3 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -7,6 +7,7 @@ #include "core/include/fpdfapi/fpdf_parser.h" #include "core/include/fxcrt/fx_string.h" +#include "third_party/base/stl_util.h" namespace { @@ -284,12 +285,10 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, case PDFOBJ_REFERENCE: { const CPDF_Reference* pRef = AsReference(); FX_DWORD obj_num = pRef->GetRefObjNum(); - if (bDirect && visited->find(obj_num) == visited->end()) { + if (bDirect && !pdfium::ContainsKey(*visited, obj_num)) { visited->insert(obj_num); - if (!pRef->GetDirect()) - return nullptr; - - return pRef->GetDirect()->CloneInternal(TRUE, visited); + auto* pDirect = pRef->GetDirect(); + return pDirect ? pDirect->CloneInternal(TRUE, visited) : nullptr; } return new CPDF_Reference(pRef->m_pObjList, obj_num); } diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index d9697000e5..d5a2780980 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -596,7 +596,7 @@ FX_BOOL CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) { return FALSE; } // Check for circular references. - if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) { + if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) { return FALSE; } } @@ -1204,7 +1204,7 @@ CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList, const int32_t offset = GetStreamFirst(pObjStream); // Read object numbers from |pObjStream| into a cache. - if (m_ObjCache.find(pObjStream) == m_ObjCache.end()) { + if (!pdfium::ContainsKey(m_ObjCache, pObjStream)) { for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) { FX_DWORD thisnum = syntax.GetDirectNum(); FX_DWORD thisoff = syntax.GetDirectNum(); @@ -1634,7 +1634,7 @@ FX_BOOL CPDF_Parser::LoadLinearizedAllCrossRefV5(FX_FILESIZE xrefpos) { return FALSE; } // Check for circular references. - if (seen_xrefpos.find(xrefpos) != seen_xrefpos.end()) { + if (pdfium::ContainsKey(seen_xrefpos, xrefpos)) { return FALSE; } } @@ -2766,7 +2766,7 @@ class CPDF_DataAvail final : public IPDF_DataAvail { CPDF_PageNode* pPageNode, IFX_DownloadHints* pHints); FX_BOOL CheckPageCount(IFX_DownloadHints* pHints); - FX_BOOL IsFirstCheck(int iPage); + bool IsFirstCheck(int iPage); void ResetFirstCheck(int iPage); FX_BOOL IsDataAvail(FX_FILESIZE offset, FX_DWORD size, @@ -3349,12 +3349,8 @@ FX_BOOL CPDF_DataAvail::PreparePageItem() { m_docStatus = PDF_DATAAVAIL_PAGETREE; return TRUE; } -FX_BOOL CPDF_DataAvail::IsFirstCheck(int iPage) { - if (m_pageMapCheckState.find(iPage) != m_pageMapCheckState.end()) - return FALSE; - - m_pageMapCheckState.insert(iPage); - return TRUE; +bool CPDF_DataAvail::IsFirstCheck(int iPage) { + return m_pageMapCheckState.insert(iPage).second; } void CPDF_DataAvail::ResetFirstCheck(int iPage) { m_pageMapCheckState.erase(iPage); @@ -4381,9 +4377,9 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) { m_objs_array.RemoveAll(); m_objnum_array.RemoveAll(); } - if (m_pagesLoadState.find(iPage) != m_pagesLoadState.end()) { + if (pdfium::ContainsKey(m_pagesLoadState, iPage)) return DataAvailable; - } + if (m_bLinearized) { if ((FX_DWORD)iPage == m_dwFirstPageNo) { m_pagesLoadState.insert(iPage); |