From 3f1c71f5a6ea058e3eec611c9dcc759b374dcb80 Mon Sep 17 00:00:00 2001 From: Oliver Chang Date: Mon, 11 Jan 2016 08:45:31 -0800 Subject: Merge to XFA: Use std::map as CPDF_Dictionary's underlying store. Replaces CFX_CMapByteStringToPtr. XFA still uses CFX_CMapByteStringToPtr so it's not completely removed just yet. Adds begin()/end() to CPDF_Dictionary and removes the GetStartPos()/GetNextElement() functions to traverse the dictionary. Callers are changed accordingly. AddValue() is also removed. TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1541703003 . (cherry picked from commit 14f39950451bb9c2a11fbc7173fd47367410f80f) Review URL: https://codereview.chromium.org/1576033002 . --- core/include/fpdfapi/fpdf_objects.h | 20 +-- core/include/fpdfdoc/fpdf_doc.h | 4 - core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp | 32 ++--- core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp | 8 +- .../fpdfapi/fpdf_page/fpdf_page_graph_state.cpp | 7 +- core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 14 +-- .../fpdfapi/fpdf_parser/fpdf_parser_objects.cpp | 138 +++++++++------------ .../src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 28 ++--- .../fpdfapi/fpdf_parser/fpdf_parser_utility.cpp | 7 +- core/src/fpdfdoc/doc_action.cpp | 31 ----- core/src/fpdfdoc/doc_formcontrol.cpp | 21 ++-- core/src/fpdfdoc/doc_utils.cpp | 47 +++---- 12 files changed, 134 insertions(+), 223 deletions(-) (limited to 'core') diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h index a9a27c74a1..5e17685e65 100644 --- a/core/include/fpdfapi/fpdf_objects.h +++ b/core/include/fpdfapi/fpdf_objects.h @@ -7,6 +7,7 @@ #ifndef CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ #define CORE_INCLUDE_FPDFAPI_FPDF_OBJECTS_H_ +#include #include #include "core/include/fxcrt/fx_coordinates.h" @@ -339,6 +340,9 @@ inline const CPDF_Array* ToArray(const CPDF_Object* obj) { class CPDF_Dictionary : public CPDF_Object { public: + using iterator = std::map::iterator; + using const_iterator = std::map::const_iterator; + CPDF_Dictionary() : CPDF_Object(PDFOBJ_DICTIONARY) {} CPDF_Object* GetElement(const CFX_ByteStringC& key) const; @@ -381,10 +385,6 @@ class CPDF_Dictionary : public CPDF_Object { FX_BOOL KeyExist(const CFX_ByteStringC& key) const; - FX_POSITION GetStartPos() const; - - CPDF_Object* GetNextElement(FX_POSITION& pos, CFX_ByteString& key) const; - void SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj); void SetAtName(const CFX_ByteStringC& key, const CFX_ByteString& name); @@ -421,14 +421,20 @@ class CPDF_Dictionary : public CPDF_Object { FX_BOOL Identical(CPDF_Dictionary* pDict) const; - int GetCount() const { return m_Map.GetCount(); } + size_t GetCount() const { return m_Map.size(); } + + iterator begin() { return m_Map.begin(); } + + iterator end() { return m_Map.end(); } + + const_iterator begin() const { return m_Map.begin(); } - void AddValue(const CFX_ByteStringC& key, CPDF_Object* pObj); + const_iterator end() const { return m_Map.end(); } protected: ~CPDF_Dictionary(); - CFX_CMapByteStringToPtr m_Map; + std::map m_Map; friend class CPDF_Object; }; diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h index ce05588f54..7a6dd4fcd4 100644 --- a/core/include/fpdfdoc/fpdf_doc.h +++ b/core/include/fpdfdoc/fpdf_doc.h @@ -298,10 +298,6 @@ class CPDF_AAction { CPDF_Action GetAction(AActionType eType) const; - FX_POSITION GetStartPos() const; - - CPDF_Action GetNextAction(FX_POSITION& pos, AActionType& eType) const; - CPDF_Dictionary* m_pDict; }; class CPDF_DocJSActions { diff --git a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp index c1ef37dab6..65bb3d985e 100644 --- a/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp +++ b/core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp @@ -15,6 +15,8 @@ #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) #define PDF_XREFSTREAM_MAXSIZE 10000 +// TODO(ochang): Make helper for appending "objnum 0 R ". + namespace { int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, @@ -112,10 +114,9 @@ int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, } offset += 2; const CPDF_Dictionary* p = pObj->AsDictionary(); - FX_POSITION pos = p->GetStartPos(); - while (pos) { - CFX_ByteString key; - CPDF_Object* pValue = p->GetNextElement(pos, key); + for (const auto& it : *p) { + const CFX_ByteString& key = it.first; + CPDF_Object* pValue = it.second; if (pFile->AppendString("/") < 0) { return -1; } @@ -184,10 +185,9 @@ int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser(); if (pParser) { CPDF_Dictionary* p = pParser->GetTrailer(); - FX_POSITION pos = p->GetStartPos(); - while (pos) { - CFX_ByteString key; - CPDF_Object* pValue = p->GetNextElement(pos, key); + for (const auto& it : *p) { + const CFX_ByteString& key = it.first; + CPDF_Object* pValue = it.second; if (key == "Encrypt" || key == "Size" || key == "Filter" || key == "Index" || key == "Length" || key == "Prev" || key == "W" || key == "XRefStm" || key == "Type" || key == "ID") { @@ -1238,11 +1238,10 @@ int32_t CPDF_Creator::WriteDirectObj(FX_DWORD objnum, m_Offset += 2; const CPDF_Dictionary* p = pObj->AsDictionary(); bool bSignDict = IsSignatureDict(p); - FX_POSITION pos = p->GetStartPos(); - while (pos) { + for (const auto& it : *p) { FX_BOOL bSignValue = FALSE; - CFX_ByteString key; - CPDF_Object* pValue = p->GetNextElement(pos, key); + const CFX_ByteString& key = it.first; + CPDF_Object* pValue = it.second; if (m_File.AppendString("/") < 0) { return -1; } @@ -1773,10 +1772,11 @@ int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) { } if (m_pParser) { CPDF_Dictionary* p = m_pParser->m_pTrailer; - FX_POSITION pos = p->GetStartPos(); - while (pos) { - CFX_ByteString key; - CPDF_Object* pValue = p->GetNextElement(pos, key); + for (const auto& it : *p) { + const CFX_ByteString& key = it.first; + CPDF_Object* pValue = it.second; + // TODO(ochang): Consolidate with similar check in + // PDF_CreatorWriteTrailer. if (key == "Encrypt" || key == "Size" || key == "Filter" || key == "Index" || key == "Length" || key == "Prev" || key == "W" || key == "XRefStm" || key == "ID") { diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp index c9eee8e380..168cbf3a61 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp @@ -1213,11 +1213,9 @@ CPDF_ColorSpace* CPDF_ColorSpace::Load(CPDF_Document* pDoc, CPDF_Object* pObj) { if (!pDict) return nullptr; - CPDF_ColorSpace* pRet = nullptr; - FX_POSITION pos = pDict->GetStartPos(); - while (pos) { - CFX_ByteString bsKey; - CPDF_Object* pValue = pDict->GetNextElement(pos, bsKey); + for (const auto& it : *pDict) { + CPDF_ColorSpace* pRet = nullptr; + CPDF_Object* pValue = it.second; if (ToName(pValue)) pRet = _CSFromName(pValue->GetString()); if (pRet) diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp index d8f21c692d..dd16aa85ce 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp @@ -458,10 +458,9 @@ void CPDF_AllStates::SetLineDash(CPDF_Array* pArray, void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, CPDF_StreamContentParser* pParser) { CPDF_GeneralStateData* pGeneralState = m_GeneralState.GetModify(); - FX_POSITION pos = pGS->GetStartPos(); - while (pos) { - CFX_ByteString key_str; - CPDF_Object* pElement = pGS->GetNextElement(pos, key_str); + for (const auto& it : *pGS) { + const CFX_ByteString& key_str = it.first; + CPDF_Object* pElement = it.second; CPDF_Object* pObject = pElement ? pElement->GetDirect() : nullptr; if (!pObject) continue; diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp index d0cf9ed719..3fbd3e486e 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -496,10 +496,9 @@ void PDF_ReplaceAbbr(CPDF_Object* pObj) { switch (pObj->GetType()) { case PDFOBJ_DICTIONARY: { CPDF_Dictionary* pDict = pObj->AsDictionary(); - FX_POSITION pos = pDict->GetStartPos(); - while (pos) { - CFX_ByteString key; - CPDF_Object* value = pDict->GetNextElement(pos, key); + for (const auto& it : *pDict) { + CFX_ByteString key = it.first; + CPDF_Object* value = it.second; CFX_ByteStringC fullname = PDF_FindFullName( PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key); if (!fullname.IsEmpty()) { @@ -544,10 +543,9 @@ void PDF_ReplaceFull(CPDF_Object* pObj) { switch (pObj->GetType()) { case PDFOBJ_DICTIONARY: { CPDF_Dictionary* pDict = pObj->AsDictionary(); - FX_POSITION pos = pDict->GetStartPos(); - while (pos) { - CFX_ByteString key; - CPDF_Object* value = pDict->GetNextElement(pos, key); + for (const auto& it : *pDict) { + CFX_ByteString key = it.first; + CPDF_Object* value = it.second; CFX_ByteStringC abbrName = PDF_FindAbbrName( PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key); if (!abbrName.IsEmpty()) { diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp index 685becaf69..2cb81002fb 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp @@ -267,12 +267,9 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect, case PDFOBJ_DICTIONARY: { CPDF_Dictionary* pCopy = new CPDF_Dictionary(); const CPDF_Dictionary* pThis = AsDictionary(); - FX_POSITION pos = pThis->m_Map.GetStartPosition(); - while (pos) { - CFX_ByteString key; - CPDF_Object* value; - pThis->m_Map.GetNextAssoc(pos, key, (void*&)value); - pCopy->m_Map.SetAt(key, value->CloneInternal(bDirect, visited)); + for (const auto& it : *pThis) { + pCopy->m_Map.insert(std::make_pair( + it.first, it.second->CloneInternal(bDirect, visited))); } return pCopy; } @@ -578,38 +575,23 @@ FX_BOOL CPDF_Array::Identical(CPDF_Array* pOther) const { return TRUE; } CPDF_Dictionary::~CPDF_Dictionary() { - FX_POSITION pos = m_Map.GetStartPosition(); - while (pos) { - if (CPDF_Object* value = static_cast(m_Map.GetNextValue(pos))) - value->Release(); - } -} -FX_POSITION CPDF_Dictionary::GetStartPos() const { - return m_Map.GetStartPosition(); -} -CPDF_Object* CPDF_Dictionary::GetNextElement(FX_POSITION& pos, - CFX_ByteString& key) const { - if (!pos) { - return NULL; + for (const auto& it : m_Map) { + it.second->Release(); } - CPDF_Object* p; - m_Map.GetNextAssoc(pos, key, (void*&)p); - return p; } CPDF_Object* CPDF_Dictionary::GetElement(const CFX_ByteStringC& key) const { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - return p; + auto it = m_Map.find(key); + if (it == m_Map.end()) + return nullptr; + return it->second; } CPDF_Object* CPDF_Dictionary::GetElementValue( const CFX_ByteStringC& key) const { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - return p ? p->GetDirect() : NULL; + CPDF_Object* p = GetElement(key); + return p ? p->GetDirect() : nullptr; } CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key) const { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); + CPDF_Object* p = GetElement(key); if (p) { return p->GetString(); } @@ -617,8 +599,7 @@ CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key) const { } CFX_ByteStringC CPDF_Dictionary::GetConstString( const CFX_ByteStringC& key) const { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); + CPDF_Object* p = GetElement(key); if (p) { return p->GetConstString(); } @@ -626,16 +607,14 @@ CFX_ByteStringC CPDF_Dictionary::GetConstString( } CFX_WideString CPDF_Dictionary::GetUnicodeText(const CFX_ByteStringC& key, CFX_CharMap* pCharMap) const { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); + CPDF_Object* p = GetElement(key); if (CPDF_Reference* pRef = ToReference(p)) p = pRef->GetDirect(); return p ? p->GetUnicodeText(pCharMap) : CFX_WideString(); } CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key, const CFX_ByteStringC& def) const { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); + CPDF_Object* p = GetElement(key); if (p) { return p->GetString(); } @@ -644,32 +623,28 @@ CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key, CFX_ByteStringC CPDF_Dictionary::GetConstString( const CFX_ByteStringC& key, const CFX_ByteStringC& def) const { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); + CPDF_Object* p = GetElement(key); if (p) { return p->GetConstString(); } return CFX_ByteStringC(def); } int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key) const { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); + CPDF_Object* p = GetElement(key); if (p) { return p->GetInteger(); } return 0; } int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key, int def) const { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); + CPDF_Object* p = GetElement(key); if (p) { return p->GetInteger(); } return def; } FX_FLOAT CPDF_Dictionary::GetNumber(const CFX_ByteStringC& key) const { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); + CPDF_Object* p = GetElement(key); if (p) { return p->GetNumber(); } @@ -677,8 +652,7 @@ FX_FLOAT CPDF_Dictionary::GetNumber(const CFX_ByteStringC& key) const { } FX_BOOL CPDF_Dictionary::GetBoolean(const CFX_ByteStringC& key, FX_BOOL bDefault) const { - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); + CPDF_Object* p = GetElement(key); if (ToBoolean(p)) return p->GetInteger(); return bDefault; @@ -714,67 +688,67 @@ CFX_Matrix CPDF_Dictionary::GetMatrix(const CFX_ByteStringC& key) const { return matrix; } FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteStringC& key) const { - void* value; - return m_Map.Lookup(key, value); + return pdfium::ContainsKey(m_Map, key); } void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj) { ASSERT(IsDictionary()); - void* pValue = nullptr; - m_Map.Lookup(key, pValue); - CPDF_Object* pExisting = static_cast(pValue); - if (pExisting == pObj) + // Avoid 2 constructions of CFX_ByteString. + CFX_ByteString key_bytestring = key; + auto it = m_Map.find(key_bytestring); + if (it == m_Map.end()) { + if (pObj) { + m_Map.insert(std::make_pair(key_bytestring, pObj)); + } return; + } - if (pExisting) - pExisting->Release(); + if (it->second == pObj) + return; + it->second->Release(); if (pObj) - m_Map.SetAt(key, pObj); + it->second = pObj; else - m_Map.RemoveKey(key); -} - -void CPDF_Dictionary::AddValue(const CFX_ByteStringC& key, CPDF_Object* pObj) { - ASSERT(m_Type == PDFOBJ_DICTIONARY); - m_Map.AddValue(key, pObj); + m_Map.erase(it); } void CPDF_Dictionary::RemoveAt(const CFX_ByteStringC& key) { ASSERT(m_Type == PDFOBJ_DICTIONARY); - CPDF_Object* p = NULL; - m_Map.Lookup(key, (void*&)p); - if (!p) { + auto it = m_Map.find(key); + if (it == m_Map.end()) return; - } - p->Release(); - m_Map.RemoveKey(key); + + it->second->Release(); + m_Map.erase(it); } void CPDF_Dictionary::ReplaceKey(const CFX_ByteStringC& oldkey, const CFX_ByteStringC& newkey) { ASSERT(m_Type == PDFOBJ_DICTIONARY); - CPDF_Object* p = NULL; - m_Map.Lookup(oldkey, (void*&)p); - if (!p) { + auto old_it = m_Map.find(oldkey); + if (old_it == m_Map.end()) return; + + // Avoid 2 constructions of CFX_ByteString. + CFX_ByteString newkey_bytestring = newkey; + auto new_it = m_Map.find(newkey_bytestring); + if (new_it != m_Map.end()) { + new_it->second->Release(); + new_it->second = old_it->second; + } else { + m_Map.insert(std::make_pair(newkey_bytestring, old_it->second)); } - m_Map.RemoveKey(oldkey); - m_Map.SetAt(newkey, p); + m_Map.erase(old_it); } FX_BOOL CPDF_Dictionary::Identical(CPDF_Dictionary* pOther) const { if (!pOther) { return FALSE; } - if (m_Map.GetCount() != pOther->m_Map.GetCount()) { + if (m_Map.size() != pOther->m_Map.size()) { return FALSE; } - FX_POSITION pos = m_Map.GetStartPosition(); - while (pos) { - CFX_ByteString key; - void* value; - m_Map.GetNextAssoc(pos, key, value); - if (!value) - return FALSE; - if (!static_cast(value)->IsIdentical(pOther->GetElement(key))) + for (const auto& it : m_Map) { + const CFX_ByteString& key = it.first; + if (!it.second->IsIdentical(pOther->GetElement(key))) return FALSE; } return TRUE; @@ -798,7 +772,7 @@ void CPDF_Dictionary::SetAtReference(const CFX_ByteStringC& key, void CPDF_Dictionary::AddReference(const CFX_ByteStringC& key, CPDF_IndirectObjects* pDoc, FX_DWORD objnum) { - AddValue(key, new CPDF_Reference(pDoc, objnum)); + SetAt(key, new CPDF_Reference(pDoc, objnum)); } void CPDF_Dictionary::SetAtNumber(const CFX_ByteStringC& key, FX_FLOAT f) { CPDF_Number* pNumber = new CPDF_Number; diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index 236ecaa837..3ab4423172 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -869,11 +869,9 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() { if (!pRoot || (pRef && IsValidObjectNumber(pRef->GetRefObjNum()) && m_ObjectInfo[pRef->GetRefObjNum()].pos != 0)) { - FX_POSITION trailer_pos = pTrailer->GetStartPos(); - while (trailer_pos) { - CFX_ByteString key; - CPDF_Object* pElement = - pTrailer->GetNextElement(trailer_pos, key); + for (const auto& it : *pTrailer) { + const CFX_ByteString& key = it.first; + CPDF_Object* pElement = it.second; FX_DWORD dwObjNum = pElement ? pElement->GetObjNum() : 0; if (dwObjNum) { @@ -2162,13 +2160,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjects* pObjList, continue; CFX_ByteStringC keyNoSlash(key.c_str() + 1, key.GetLength() - 1); - // TODO(thestig): Remove this conditional once CPDF_Dictionary has a - // better underlying map implementation. - if (nKeys < 32) { - pDict->SetAt(keyNoSlash, pObj); - } else { - pDict->AddValue(keyNoSlash, pObj); - } + pDict->SetAt(keyNoSlash, pObj); } if (IsSignatureDict(pDict.get())) { @@ -2315,8 +2307,8 @@ CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( return nullptr; } if (key.GetLength() > 1) { - pDict->AddValue(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1), - obj.release()); + pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1), + obj.release()); } } if (pContext) { @@ -3058,11 +3050,9 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail( if (pDict && pDict->GetString("Type") == "Page" && !bParsePage) { continue; } - FX_POSITION pos = pDict->GetStartPos(); - while (pos) { - CPDF_Object* value; - CFX_ByteString key; - value = pDict->GetNextElement(pos, key); + for (const auto& it : *pDict) { + const CFX_ByteString& key = it.first; + CPDF_Object* value = it.second; if (key != "Parent") { new_obj_array.Add(value); } diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp index ec155a8d02..1abf665d65 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp @@ -383,10 +383,9 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) { case PDFOBJ_DICTIONARY: { const CPDF_Dictionary* p = pObj->AsDictionary(); buf << "<<"; - FX_POSITION pos = p->GetStartPos(); - while (pos) { - CFX_ByteString key; - CPDF_Object* pValue = p->GetNextElement(pos, key); + for (const auto& it : *p) { + const CFX_ByteString& key = it.first; + CPDF_Object* pValue = it.second; buf << "/" << PDF_NameEncode(key); if (pValue && pValue->GetObjNum()) { buf << " " << pValue->GetObjNum() << " 0 R "; diff --git a/core/src/fpdfdoc/doc_action.cpp b/core/src/fpdfdoc/doc_action.cpp index e68a8c8a06..28d17cd673 100644 --- a/core/src/fpdfdoc/doc_action.cpp +++ b/core/src/fpdfdoc/doc_action.cpp @@ -257,37 +257,6 @@ CPDF_Action CPDF_AAction::GetAction(AActionType eType) const { } return CPDF_Action(m_pDict->GetDict(g_sAATypes[(int)eType])); } -FX_POSITION CPDF_AAction::GetStartPos() const { - if (!m_pDict) { - return NULL; - } - return m_pDict->GetStartPos(); -} -CPDF_Action CPDF_AAction::GetNextAction(FX_POSITION& pos, - AActionType& eType) const { - if (!m_pDict) { - return CPDF_Action(); - } - CFX_ByteString csKey; - CPDF_Object* pObj = m_pDict->GetNextElement(pos, csKey); - if (!pObj) { - return CPDF_Action(); - } - CPDF_Object* pDirect = pObj->GetDirect(); - CPDF_Dictionary* pDict = ToDictionary(pDirect); - if (!pDict) - return CPDF_Action(); - - int i = 0; - while (g_sAATypes[i][0] != '\0') { - if (csKey == g_sAATypes[i]) { - break; - } - i++; - } - eType = (AActionType)i; - return CPDF_Action(pDict); -} CPDF_DocJSActions::CPDF_DocJSActions(CPDF_Document* pDoc) : m_pDocument(pDoc) {} diff --git a/core/src/fpdfdoc/doc_formcontrol.cpp b/core/src/fpdfdoc/doc_formcontrol.cpp index 93e837feaf..bd339e375c 100644 --- a/core/src/fpdfdoc/doc_formcontrol.cpp +++ b/core/src/fpdfdoc/doc_formcontrol.cpp @@ -27,11 +27,9 @@ CFX_ByteString CPDF_FormControl::GetOnStateName() { if (!pN) { return csOn; } - FX_POSITION pos = pN->GetStartPos(); - while (pos) { - pN->GetNextElement(pos, csOn); - if (csOn != "Off") { - return csOn; + for (const auto& it : *pN) { + if (it.first != "Off") { + return it.first; } } return CFX_ByteString(); @@ -54,10 +52,8 @@ void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) { if (!pAP) { return; } - FX_POSITION pos1 = pAP->GetStartPos(); - while (pos1) { - CFX_ByteString csKey1; - CPDF_Object* pObj1 = pAP->GetNextElement(pos1, csKey1); + for (const auto& it : *pAP) { + CPDF_Object* pObj1 = it.second; if (!pObj1) { continue; } @@ -66,10 +62,9 @@ void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) { if (!pSubDict) continue; - FX_POSITION pos2 = pSubDict->GetStartPos(); - while (pos2) { - CFX_ByteString csKey2; - CPDF_Object* pObj2 = pSubDict->GetNextElement(pos2, csKey2); + for (const auto& subdict_it : *pSubDict) { + const CFX_ByteString& csKey2 = subdict_it.first; + CPDF_Object* pObj2 = subdict_it.second; if (!pObj2) { continue; } diff --git a/core/src/fpdfdoc/doc_utils.cpp b/core/src/fpdfdoc/doc_utils.cpp index 01a7470ef0..89836739b3 100644 --- a/core/src/fpdfdoc/doc_utils.cpp +++ b/core/src/fpdfdoc/doc_utils.cpp @@ -279,11 +279,8 @@ FX_DWORD CountInterFormFonts(CPDF_Dictionary* pFormDict) { return 0; } FX_DWORD dwCount = 0; - FX_POSITION pos = pFonts->GetStartPos(); - while (pos) { - CPDF_Object* pObj = NULL; - CFX_ByteString csKey; - pObj = pFonts->GetNextElement(pos, csKey); + for (const auto& it : *pFonts) { + CPDF_Object* pObj = it.second; if (!pObj) { continue; } @@ -311,11 +308,9 @@ CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, return NULL; } FX_DWORD dwCount = 0; - FX_POSITION pos = pFonts->GetStartPos(); - while (pos) { - CPDF_Object* pObj = NULL; - CFX_ByteString csKey; - pObj = pFonts->GetNextElement(pos, csKey); + for (const auto& it : *pFonts) { + const CFX_ByteString& csKey = it.first; + CPDF_Object* pObj = it.second; if (!pObj) { continue; } @@ -371,11 +366,9 @@ CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, if (!pFonts) { return NULL; } - FX_POSITION pos = pFonts->GetStartPos(); - while (pos) { - CPDF_Object* pObj = NULL; - CFX_ByteString csKey; - pObj = pFonts->GetNextElement(pos, csKey); + for (const auto& it : *pFonts) { + const CFX_ByteString& csKey = it.first; + CPDF_Object* pObj = it.second; if (!pObj) { continue; } @@ -414,11 +407,9 @@ CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, if (!pFonts) { return NULL; } - FX_POSITION pos = pFonts->GetStartPos(); - while (pos) { - CPDF_Object* pObj = NULL; - CFX_ByteString csKey; - pObj = pFonts->GetNextElement(pos, csKey); + for (const auto& it : *pFonts) { + const CFX_ByteString& csKey = it.first; + CPDF_Object* pObj = it.second; if (!pObj) { continue; } @@ -472,11 +463,9 @@ FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, if (!pFonts) { return FALSE; } - FX_POSITION pos = pFonts->GetStartPos(); - while (pos) { - CPDF_Object* pObj = NULL; - CFX_ByteString csKey; - pObj = pFonts->GetNextElement(pos, csKey); + for (const auto& it : *pFonts) { + const CFX_ByteString& csKey = it.first; + CPDF_Object* pObj = it.second; if (!pObj) { continue; } @@ -512,11 +501,9 @@ FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, if (csFontName.GetLength() > 0) { csFontName.Remove(' '); } - FX_POSITION pos = pFonts->GetStartPos(); - while (pos) { - CPDF_Object* pObj = NULL; - CFX_ByteString csKey, csTmp; - pObj = pFonts->GetNextElement(pos, csKey); + for (const auto& it : *pFonts) { + const CFX_ByteString& csKey = it.first; + CPDF_Object* pObj = it.second; if (!pObj) { continue; } -- cgit v1.2.3