Replace CFX_MapPtrTemplate with std::map.

R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/1181593003.
diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h
index cb91b96..fc9d3bc 100644
--- a/core/include/fpdfdoc/fpdf_doc.h
+++ b/core/include/fpdfdoc/fpdf_doc.h
@@ -7,6 +7,8 @@
 #ifndef CORE_INCLUDE_FPDFDOC_FPDF_DOC_H_
 #define CORE_INCLUDE_FPDFDOC_FPDF_DOC_H_
 
+#include <map>
+
 #include "../fpdfapi/fpdf_parser.h"
 #include "../fpdfapi/fpdf_render.h"
 
@@ -181,7 +183,7 @@
 
     UsageType			m_eUsageType;
 
-    CFX_MapPtrTemplate<const CPDF_Dictionary*, void*>	m_OCGStates;
+    std::map<const CPDF_Dictionary*, FX_BOOL> m_OCGStates;
 };
 class CPDF_LWinParam
 {
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h
index 0083825..d575df6 100644
--- a/core/include/fxcrt/fx_basic.h
+++ b/core/include/fxcrt/fx_basic.h
@@ -853,46 +853,7 @@
 
     CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const;
 };
-template <class KeyType, class ValueType>
-class CFX_MapPtrTemplate : public CFX_MapPtrToPtr
-{
-public:
-    CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {}
 
-    FX_BOOL	Lookup(KeyType key, ValueType& rValue) const
-    {
-        void* pValue = NULL;
-        if (!CFX_MapPtrToPtr::Lookup((void*)(uintptr_t)key, pValue)) {
-            return FALSE;
-        }
-        rValue = (ValueType)(uintptr_t)pValue;
-        return TRUE;
-    }
-
-    ValueType& operator[](KeyType key)
-    {
-        return (ValueType&)CFX_MapPtrToPtr::operator []((void*)(uintptr_t)key);
-    }
-
-    void SetAt(KeyType key, ValueType newValue)
-    {
-        CFX_MapPtrToPtr::SetAt((void*)(uintptr_t)key, (void*)(uintptr_t)newValue);
-    }
-
-    FX_BOOL	RemoveKey(KeyType key)
-    {
-        return CFX_MapPtrToPtr::RemoveKey((void*)(uintptr_t)key);
-    }
-
-    void GetNextAssoc(FX_POSITION& rNextPosition, KeyType& rKey, ValueType& rValue) const
-    {
-        void* pKey = NULL;
-        void* pValue = NULL;
-        CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue);
-        rKey = (KeyType)(uintptr_t)pKey;
-        rValue = (ValueType)(uintptr_t)pValue;
-    }
-};
 class CFX_CMapDWordToDWord
 {
 public:
diff --git a/core/include/fxge/fx_font.h b/core/include/fxge/fx_font.h
index 31794d6..5a0a3b2 100644
--- a/core/include/fxge/fx_font.h
+++ b/core/include/fxge/fx_font.h
@@ -7,6 +7,8 @@
 #ifndef CORE_INCLUDE_FXGE_FX_FONT_H_
 #define CORE_INCLUDE_FXGE_FX_FONT_H_
 
+#include <map>
+
 #include "../fxcrt/fx_system.h"
 #include "fx_dib.h"
 
@@ -343,7 +345,7 @@
     CFX_FaceCache*	m_Obj;
     FX_DWORD		m_nCount;
 };
-typedef CFX_MapPtrTemplate<FXFT_Face, CFX_CountedFaceCache*> CFX_FTCacheMap;
+
 class CFX_FontCache
 {
 public:
@@ -353,8 +355,9 @@
     void					FreeCache(FX_BOOL bRelease = FALSE);
 
 private:
-    CFX_FTCacheMap			m_FTFaceMap;
-    CFX_FTCacheMap			m_ExtFaceMap;
+    using CFX_FTCacheMap = std::map<FXFT_Face, CFX_CountedFaceCache*>;
+    CFX_FTCacheMap m_FTFaceMap;
+    CFX_FTCacheMap m_ExtFaceMap;
 };
 class CFX_AutoFontCache
 {
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
index 06c9ea6..c4a9d77 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp
@@ -11,43 +11,38 @@
 #include "render_int.h"
 
 CPDF_DocRenderData::CPDF_DocRenderData(CPDF_Document* pPDFDoc)
-    : m_pPDFDoc(pPDFDoc)
-    , m_pFontCache(NULL)
+    : m_pPDFDoc(pPDFDoc),
+      m_pFontCache(new CFX_FontCache)
 {
 }
+
 CPDF_DocRenderData::~CPDF_DocRenderData()
 {
     Clear(TRUE);
 }
+
 void CPDF_DocRenderData::Clear(FX_BOOL bRelease)
 {
-    FX_POSITION pos;
-    {
-        pos = m_Type3FaceMap.GetStartPosition();
-        while (pos) {
-            CPDF_Font* pFont;
-            CPDF_CountedObject<CPDF_Type3Cache>* cache;
-            m_Type3FaceMap.GetNextAssoc(pos, pFont, cache);
-            if (bRelease || cache->use_count() < 2) {
-                delete cache->get();
-                delete cache;
-                m_Type3FaceMap.RemoveKey(pFont);
-            }
+    for (auto it = m_Type3FaceMap.begin(); it != m_Type3FaceMap.end();) {
+        auto curr_it = it++;
+        CPDF_CountedObject<CPDF_Type3Cache>* cache = curr_it->second;
+        if (bRelease || cache->use_count() < 2) {
+            delete cache->get();
+            delete cache;
+            m_Type3FaceMap.erase(curr_it);
         }
     }
-    {
-        pos = m_TransferFuncMap.GetStartPosition();
-        while (pos) {
-            CPDF_Object* key;
-            CPDF_CountedObject<CPDF_TransferFunc>* value;
-            m_TransferFuncMap.GetNextAssoc(pos, key, value);
-            if (bRelease || value->use_count() < 2) {
-                delete value->get();
-                delete value;
-                m_TransferFuncMap.RemoveKey(key);
-            }
+
+    for (auto it = m_TransferFuncMap.begin(); it != m_TransferFuncMap.end();) {
+        auto curr_it = it++;
+        CPDF_CountedObject<CPDF_TransferFunc>* value = curr_it->second;
+        if (bRelease || value->use_count() < 2) {
+            delete value->get();
+            delete value;
+            m_TransferFuncMap.erase(curr_it);
         }
     }
+
     if (m_pFontCache) {
         if (bRelease) {
             delete m_pFontCache;
@@ -57,26 +52,26 @@
         }
     }
 }
-FX_BOOL CPDF_DocRenderData::Initialize()
-{
-    m_pFontCache = new CFX_FontCache;
-    return TRUE;
-}
+
 CPDF_Type3Cache* CPDF_DocRenderData::GetCachedType3(CPDF_Type3Font* pFont)
 {
     CPDF_CountedObject<CPDF_Type3Cache>* pCache;
-    if (!m_Type3FaceMap.Lookup(pFont, pCache)) {
+    auto it = m_Type3FaceMap.find(pFont);
+    if (it == m_Type3FaceMap.end()) {
         CPDF_Type3Cache* pType3 = new CPDF_Type3Cache(pFont);
         pCache = new CPDF_CountedObject<CPDF_Type3Cache>(pType3);
-        m_Type3FaceMap.SetAt(pFont, pCache);
+        m_Type3FaceMap[pFont] = pCache;
+    } else {
+        pCache = it->second;
     }
     return pCache->AddRef();
 }
+
 void CPDF_DocRenderData::ReleaseCachedType3(CPDF_Type3Font* pFont)
 {
-    CPDF_CountedObject<CPDF_Type3Cache>* pCache;
-    if (m_Type3FaceMap.Lookup(pFont, pCache))
-        pCache->RemoveRef();
+    auto it = m_Type3FaceMap.find(pFont);
+    if (it != m_Type3FaceMap.end())
+        it->second->RemoveRef();
 }
 
 class CPDF_RenderModule : public IPDF_RenderModule
@@ -114,9 +109,7 @@
 
 CPDF_DocRenderData*	CPDF_RenderModule::CreateDocData(CPDF_Document* pDoc)
 {
-    CPDF_DocRenderData* pData = new CPDF_DocRenderData(pDoc);
-    pData->Initialize();
-    return pData;
+    return new CPDF_DocRenderData(pDoc);
 }
 void CPDF_RenderModule::DestroyDocData(CPDF_DocRenderData* pDocData)
 {
@@ -1183,85 +1176,83 @@
 }
 CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj)
 {
-    if (pObj == NULL) {
-        return NULL;
+    if (!pObj)
+        return nullptr;
+
+    auto it = m_TransferFuncMap.find(pObj);
+    if (it != m_TransferFuncMap.end()) {
+        CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter = it->second;
+        return pTransferCounter->AddRef();
     }
-    CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter;
-    if (!m_TransferFuncMap.Lookup(pObj, pTransferCounter)) {
-        CPDF_TransferFunc* pTransfer = NULL;
-        CPDF_Function* pFuncs[3] = {NULL, NULL, NULL};
-        FX_BOOL bUniTransfer = TRUE;
-        int i;
-        FX_BOOL bIdentity = TRUE;
-        if (pObj->GetType() == PDFOBJ_ARRAY) {
-            bUniTransfer = FALSE;
-            CPDF_Array* pArray = (CPDF_Array*)pObj;
-            if (pArray->GetCount() < 3) {
-                return NULL;
+
+    CPDF_Function* pFuncs[3] = { nullptr, nullptr, nullptr };
+    FX_BOOL bUniTransfer = TRUE;
+    FX_BOOL bIdentity = TRUE;
+    if (pObj->GetType() == PDFOBJ_ARRAY) {
+        bUniTransfer = FALSE;
+        CPDF_Array* pArray = (CPDF_Array*)pObj;
+        if (pArray->GetCount() < 3)
+            return nullptr;
+
+        for (FX_DWORD i = 0; i < 3; ++i) {
+            pFuncs[2 - i] = CPDF_Function::Load(pArray->GetElementValue(i));
+            if (!pFuncs[2 - i]) {
+                return nullptr;
             }
-            for (FX_DWORD i = 0; i < 3; i ++) {
-                pFuncs[2 - i] = CPDF_Function::Load(pArray->GetElementValue(i));
-                if (pFuncs[2 - i] == NULL) {
-                    return NULL;
-                }
+        }
+    } else {
+        pFuncs[0] = CPDF_Function::Load(pObj);
+        if (!pFuncs[0]) {
+            return nullptr;
+        }
+    }
+    CPDF_TransferFunc* pTransfer = new CPDF_TransferFunc;
+    pTransfer->m_pPDFDoc = m_pPDFDoc;
+    CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter =
+        new CPDF_CountedObject<CPDF_TransferFunc>(pTransfer);
+    m_TransferFuncMap[pObj] = pTransferCounter;
+    static const int kMaxOutputs = 16;
+    FX_FLOAT output[kMaxOutputs];
+    FXSYS_memset(output, 0, sizeof(output));
+    FX_FLOAT input;
+    int noutput;
+    for (int v = 0; v < 256; ++v) {
+        input = (FX_FLOAT)v / 255.0f;
+        if (bUniTransfer) {
+            if (pFuncs[0] && pFuncs[0]->CountOutputs() <= kMaxOutputs)
+                pFuncs[0]->Call(&input, 1, output, noutput);
+            int o = FXSYS_round(output[0] * 255);
+            if (o != v)
+                bIdentity = FALSE;
+            for (int i = 0; i < 3; ++i) {
+                pTransfer->m_Samples[i * 256 + v] = o;
             }
         } else {
-            pFuncs[0] = CPDF_Function::Load(pObj);
-            if (pFuncs[0] == NULL) {
-                return NULL;
-            }
-        }
-        pTransfer = new CPDF_TransferFunc;
-        pTransfer->m_pPDFDoc = m_pPDFDoc;
-        pTransferCounter = new CPDF_CountedObject<CPDF_TransferFunc>(pTransfer);
-        m_TransferFuncMap.SetAt(pObj, pTransferCounter);
-        static const int kMaxOutputs = 16;
-        FX_FLOAT output[kMaxOutputs];
-        FXSYS_memset(output, 0, sizeof(output));
-        FX_FLOAT input;
-        int noutput;
-        for (int v = 0; v < 256; v ++) {
-            input = (FX_FLOAT)v / 255.0f;
-            if (bUniTransfer) {
-                if (pFuncs[0] && pFuncs[0]->CountOutputs() <= kMaxOutputs) {
-                    pFuncs[0]->Call(&input, 1, output, noutput);
-                }
-                int o = FXSYS_round(output[0] * 255);
-                if (o != v) {
-                    bIdentity = FALSE;
-                }
-                for (i = 0; i < 3; i ++) {
+            for (int i = 0; i < 3; ++i) {
+                if (pFuncs[i] && pFuncs[i]->CountOutputs() <= kMaxOutputs) {
+                    pFuncs[i]->Call(&input, 1, output, noutput);
+                    int o = FXSYS_round(output[0] * 255);
+                    if (o != v)
+                        bIdentity = FALSE;
                     pTransfer->m_Samples[i * 256 + v] = o;
+                } else {
+                    pTransfer->m_Samples[i * 256 + v] = v;
                 }
-            } else
-                for (i = 0; i < 3; i ++) {
-                    if (pFuncs[i] && pFuncs[i]->CountOutputs() <= kMaxOutputs) {
-                        pFuncs[i]->Call(&input, 1, output, noutput);
-                        int o = FXSYS_round(output[0] * 255);
-                        if (o != v) {
-                            bIdentity = FALSE;
-                        }
-                        pTransfer->m_Samples[i * 256 + v] = o;
-                    } else {
-                        pTransfer->m_Samples[i * 256 + v] = v;
-                    }
-                }
-        }
-        for (i = 0; i < 3; i ++)
-            if (pFuncs[i]) {
-                delete pFuncs[i];
             }
-        pTransfer->m_bIdentity = bIdentity;
+        }
     }
+    for (int i = 0; i < 3; ++i)
+        delete pFuncs[i];
+
+    pTransfer->m_bIdentity = bIdentity;
     return pTransferCounter->AddRef();
 }
+
 void CPDF_DocRenderData::ReleaseTransferFunc(CPDF_Object* pObj)
 {
-    CPDF_CountedObject<CPDF_TransferFunc>* pTransferCounter;
-    if (!m_TransferFuncMap.Lookup(pObj, pTransferCounter)) {
-        return;
-    }
-    pTransferCounter->RemoveRef();
+    auto it = m_TransferFuncMap.find(pObj);
+    if (it != m_TransferFuncMap.end())
+        it->second->RemoveRef();
 }
 CPDF_RenderConfig::CPDF_RenderConfig()
 {
diff --git a/core/src/fpdfapi/fpdf_render/render_int.h b/core/src/fpdfapi/fpdf_render/render_int.h
index 7aa8358..77acb15 100644
--- a/core/src/fpdfapi/fpdf_render/render_int.h
+++ b/core/src/fpdfapi/fpdf_render/render_int.h
@@ -7,6 +7,8 @@
 #ifndef CORE_SRC_FPDFAPI_FPDF_RENDER_RENDER_INT_H_
 #define CORE_SRC_FPDFAPI_FPDF_RENDER_RENDER_INT_H_
 
+#include <map>
+
 #include "../../../../third_party/base/nonstd_unique_ptr.h"
 #include "../../../include/fpdfapi/fpdf_pageobj.h"
 
@@ -52,14 +54,12 @@
     CFX_DIBSource*	TranslateImage(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc);
     FX_COLORREF		TranslateColor(FX_COLORREF src);
 };
-typedef CFX_MapPtrTemplate<CPDF_Font*, CPDF_CountedObject<CPDF_Type3Cache>*> CPDF_Type3CacheMap;
-typedef CFX_MapPtrTemplate<CPDF_Object*, CPDF_CountedObject<CPDF_TransferFunc>*> CPDF_TransferFuncMap;
+
 class CPDF_DocRenderData
 {
 public:
     CPDF_DocRenderData(CPDF_Document* pPDFDoc = NULL);
     ~CPDF_DocRenderData();
-    FX_BOOL				Initialize();
     CPDF_Type3Cache*	GetCachedType3(CPDF_Type3Font* pFont);
     CPDF_TransferFunc*	GetTransferFunc(CPDF_Object* pObj);
     CFX_FontCache*		GetFontCache()
@@ -70,10 +70,15 @@
     void				ReleaseCachedType3(CPDF_Type3Font* pFont);
     void				ReleaseTransferFunc(CPDF_Object* pObj);
 private:
-    CPDF_Document*		m_pPDFDoc;
-    CFX_FontCache*		m_pFontCache;
-    CPDF_Type3CacheMap	m_Type3FaceMap;
-    CPDF_TransferFuncMap	m_TransferFuncMap;
+    using CPDF_Type3CacheMap =
+        std::map<CPDF_Font*, CPDF_CountedObject<CPDF_Type3Cache>*>;
+    using CPDF_TransferFuncMap =
+        std::map<CPDF_Object*, CPDF_CountedObject<CPDF_TransferFunc>*> ;
+
+    CPDF_Document* m_pPDFDoc;
+    CFX_FontCache* m_pFontCache;
+    CPDF_Type3CacheMap m_Type3FaceMap;
+    CPDF_TransferFuncMap m_TransferFuncMap;
 };
 struct _PDF_RenderItem {
 public:
diff --git a/core/src/fpdfdoc/doc_ocg.cpp b/core/src/fpdfdoc/doc_ocg.cpp
index 601b006..8477cb8 100644
--- a/core/src/fpdfdoc/doc_ocg.cpp
+++ b/core/src/fpdfdoc/doc_ocg.cpp
@@ -99,7 +99,7 @@
 }
 CPDF_OCContext::~CPDF_OCContext()
 {
-    m_OCGStates.RemoveAll();
+    m_OCGStates.clear();
 }
 FX_BOOL CPDF_OCContext::LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig, const CPDF_Dictionary *pOCGDict, FX_BOOL &bValidConfig) const
 {
@@ -174,19 +174,21 @@
     FX_BOOL bDefValid = FALSE;
     return LoadOCGStateFromConfig(csState, pOCGDict, bDefValid);
 }
-FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary *pOCGDict)
+
+FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict)
 {
-    if (!pOCGDict) {
+    if (!pOCGDict)
         return FALSE;
-    }
-    void* bState = NULL;
-    if (m_OCGStates.Lookup(pOCGDict, bState)) {
-        return (uintptr_t)bState != 0;
-    }
-    bState = (void*)(uintptr_t)LoadOCGState(pOCGDict);
-    m_OCGStates.SetAt(pOCGDict, bState);
-    return (uintptr_t)bState != 0;
+
+    const auto it = m_OCGStates.find(pOCGDict);
+    if (it != m_OCGStates.end())
+        return it->second;
+
+    FX_BOOL bState = LoadOCGState(pOCGDict);
+    m_OCGStates[pOCGDict] = bState;
+    return bState;
 }
+
 FX_BOOL CPDF_OCContext::GetOCGVE(CPDF_Array *pExpression, FX_BOOL bFromConfig, int nLevel)
 {
     if (nLevel > 32) {
@@ -296,5 +298,5 @@
 }
 void CPDF_OCContext::ResetOCContext()
 {
-    m_OCGStates.RemoveAll();
+    m_OCGStates.clear();
 }
diff --git a/core/src/fxge/ge/fx_ge_text.cpp b/core/src/fxge/ge/fx_ge_text.cpp
index b55119b..d15db7b 100644
--- a/core/src/fxge/ge/fx_ge_text.cpp
+++ b/core/src/fxge/ge/fx_ge_text.cpp
@@ -1002,64 +1002,70 @@
 {
     FreeCache(TRUE);
 }
+
 CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont)
 {
-    FX_BOOL bExternal = pFont->GetFace() == NULL;
-    void* face = bExternal ? pFont->GetSubstFont()->m_ExtHandle : pFont->GetFace();
-    CFX_FTCacheMap& map =  bExternal ? m_ExtFaceMap : m_FTFaceMap;
-    CFX_CountedFaceCache* counted_face_cache = NULL;
-    if (map.Lookup((FXFT_Face)face, counted_face_cache)) {
+    FXFT_Face internal_face = pFont->GetFace();
+    const FX_BOOL bExternal = internal_face == nullptr;
+    FXFT_Face face = bExternal ?
+        (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face;
+    CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
+    auto it = map.find(face);
+    if (it != map.end()) {
+        CFX_CountedFaceCache* counted_face_cache = it->second;
         counted_face_cache->m_nCount++;
         return counted_face_cache->m_Obj;
     }
-    CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? NULL : (FXFT_Face)face);
-    counted_face_cache = new CFX_CountedFaceCache;
+
+    CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face);
+    CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache;
     counted_face_cache->m_nCount = 2;
     counted_face_cache->m_Obj = face_cache;
-    map.SetAt((FXFT_Face)face, counted_face_cache);
+    map[face] = counted_face_cache;
     return face_cache;
 }
+
 void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont)
 {
-    FX_BOOL bExternal = pFont->GetFace() == NULL;
-    void* face = bExternal ? pFont->GetSubstFont()->m_ExtHandle : pFont->GetFace();
+    FXFT_Face internal_face = pFont->GetFace();
+    const FX_BOOL bExternal = internal_face == nullptr;
+    FXFT_Face face = bExternal ?
+        (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face;
     CFX_FTCacheMap& map =  bExternal ? m_ExtFaceMap : m_FTFaceMap;
-    CFX_CountedFaceCache* counted_face_cache = NULL;
-    if (!map.Lookup((FXFT_Face)face, counted_face_cache)) {
+
+    auto it = map.find(face);
+    if (it == map.end())
         return;
-    }
+
+    CFX_CountedFaceCache* counted_face_cache = it->second;
     if (counted_face_cache->m_nCount > 1) {
         counted_face_cache->m_nCount--;
     }
 }
+
 void CFX_FontCache::FreeCache(FX_BOOL bRelease)
 {
-    {
-        FX_POSITION pos;
-        pos = m_FTFaceMap.GetStartPosition();
-        while (pos) {
-            FXFT_Face face;
-            CFX_CountedFaceCache* cache;
-            m_FTFaceMap.GetNextAssoc(pos, face, cache);
-            if (bRelease || cache->m_nCount < 2) {
-                delete cache->m_Obj;
-                delete cache;
-                m_FTFaceMap.RemoveKey(face);
-            }
+    for (auto it = m_FTFaceMap.begin(); it != m_FTFaceMap.end();) {
+        auto curr_it = it++;
+        CFX_CountedFaceCache* cache = curr_it->second;
+        if (bRelease || cache->m_nCount < 2) {
+            delete cache->m_Obj;
+            delete cache;
+            m_FTFaceMap.erase(curr_it);
         }
-        pos = m_ExtFaceMap.GetStartPosition();
-        while (pos) {
-            FXFT_Face face;
-            CFX_CountedFaceCache* cache;
-            m_ExtFaceMap.GetNextAssoc(pos, face, cache);
-            if (bRelease || cache->m_nCount < 2) {
-                delete cache->m_Obj;
-                delete cache;
-                m_ExtFaceMap.RemoveKey(face);
-            }
+    }
+
+    for (auto it = m_ExtFaceMap.begin(); it != m_ExtFaceMap.end();) {
+        auto curr_it = it++;
+        CFX_CountedFaceCache* cache = curr_it->second;
+        if (bRelease || cache->m_nCount < 2) {
+            delete cache->m_Obj;
+            delete cache;
+            m_ExtFaceMap.erase(curr_it);
         }
     }
 }
+
 CFX_FaceCache::CFX_FaceCache(FXFT_Face face)
 {
     m_Face = face;
diff --git a/fpdfsdk/include/formfiller/FFL_FormFiller.h b/fpdfsdk/include/formfiller/FFL_FormFiller.h
index e4e04f3..52e1193 100644
--- a/fpdfsdk/include/formfiller/FFL_FormFiller.h
+++ b/fpdfsdk/include/formfiller/FFL_FormFiller.h
@@ -19,8 +19,6 @@
 class CPDFSDK_Widget;
 
 
-#define CFFL_PageView2PDFWindow		CFX_MapPtrTemplate<CPDFSDK_PageView*, CPWL_Wnd*>
-
 struct FFL_KeyStrokeData
 {
 	CFX_WideString		swValue;
@@ -78,11 +76,10 @@
 	virtual void				DoCut(CPDFSDK_Document* pDocument);
 	virtual void				DoPaste(CPDFSDK_Document* pDocument);
 
-public: //CPWL_TimerHandler
+        // CPWL_TimerHandler
 	virtual void				TimerProc();
 	virtual IFX_SystemHandler*	GetSystemHandler() const;
 
-public:
 	virtual CPDF_Matrix			GetWindowMatrix(void* pAttachedData);
 	virtual CFX_WideString		LoadPopupMenuString(int nIndex);
 
@@ -121,7 +118,6 @@
 
 	virtual void				GetKeyStrokeData(CPDFSDK_PageView* pPageView, FFL_KeyStrokeData& data);
 
-public:
 	CPWL_Wnd*					GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew);
 	void						DestroyPDFWindow(CPDFSDK_PageView* pPageView);
 	void						EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow);
@@ -130,7 +126,6 @@
 	virtual CPWL_Wnd*			NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView) = 0;
 	virtual CPDF_Rect			GetFocusBox(CPDFSDK_PageView* pPageView);
 
-public:
 	FX_BOOL						IsValid() const;
 	CPDF_Rect					GetPDFWindowRect() const;
 
@@ -140,14 +135,17 @@
 	virtual void				InvalidateRect(double left, double top, double right, double bottom);
 	CPDFDoc_Environment*		GetApp(){return m_pApp;}
 	CPDFSDK_Annot*				GetSDKAnnot() {return m_pAnnot;}
-protected:
-	CPDFDoc_Environment*		m_pApp;
-	CPDFSDK_Widget*				m_pWidget;
-	CPDFSDK_Annot*				m_pAnnot;
 
-	FX_BOOL						m_bValid;
-	CFFL_PageView2PDFWindow		m_Maps;
-	CPDF_Point					m_ptOldPos;
+protected:
+    using CFFL_PageView2PDFWindow = std::map<CPDFSDK_PageView*, CPWL_Wnd*>;
+
+    CPDFDoc_Environment* m_pApp;
+    CPDFSDK_Widget* m_pWidget;
+    CPDFSDK_Annot* m_pAnnot;
+
+    FX_BOOL m_bValid;
+    CFFL_PageView2PDFWindow m_Maps;
+    CPDF_Point m_ptOldPos;
 };
 
 class CFFL_Button : public CFFL_FormFiller
diff --git a/fpdfsdk/include/formfiller/FFL_IFormFiller.h b/fpdfsdk/include/formfiller/FFL_IFormFiller.h
index ddcc2c5..b27d1e68 100644
--- a/fpdfsdk/include/formfiller/FFL_IFormFiller.h
+++ b/fpdfsdk/include/formfiller/FFL_IFormFiller.h
@@ -7,13 +7,13 @@
 #ifndef FPDFSDK_INCLUDE_FORMFILLER_FFL_IFORMFILLER_H_
 #define FPDFSDK_INCLUDE_FORMFILLER_FFL_IFORMFILLER_H_
 
+#include <map>
+
 #include "FormFiller.h"
 
 class CFFL_FormFiller;
 class CFFL_PrivateData;
 
-#define CFFL_Widget2Filler		CFX_MapPtrTemplate<CPDFSDK_Annot*, CFFL_FormFiller*>
-
 class CFFL_IFormFiller : public IPWL_Filler_Notify
 {
 public:
@@ -52,7 +52,6 @@
 	virtual FX_BOOL				OnSetFocus(CPDFSDK_Annot* pAnnot,FX_UINT nFlag);
 	virtual FX_BOOL				OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag);
 
-public:
 	virtual void				QueryWherePopup(void* pPrivateData, FX_FLOAT fPopupMin,FX_FLOAT fPopupMax, int32_t & nRet, FX_FLOAT & fPopupRet);
 	virtual void				OnBeforeKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, int32_t nKeyCode,
 										CFX_WideString & strChange, const CFX_WideString& strChangeEx,
@@ -64,13 +63,11 @@
 	virtual void				OnKeyStroke(FX_BOOL bEditOrList, void* pPrivateData, int32_t nKeyCode, CFX_WideString & strChange,
 									const CFX_WideString& strChangeEx, FX_BOOL bKeyDown, FX_BOOL & bRC, FX_BOOL & bExit);
 
-public:
 	virtual void				BeforeUndo(CPDFSDK_Document* pDocument);
 	virtual void				BeforeRedo(CPDFSDK_Document* pDocument);
 	virtual void				AfterUndo(CPDFSDK_Document* pDocument);
 	virtual void				AfterRedo(CPDFSDK_Document* pDocument);
 
-public:
 	virtual FX_BOOL				CanCopy(CPDFSDK_Document* pDocument);
 	virtual FX_BOOL				CanCut(CPDFSDK_Document* pDocument);
 	virtual FX_BOOL				CanPaste(CPDFSDK_Document* pDocument);
@@ -79,7 +76,6 @@
 	virtual void				DoCut(CPDFSDK_Document* pDocument);
 	virtual void				DoPaste(CPDFSDK_Document* pDocument);
 
-public:
 	CFFL_FormFiller*			GetFormFiller(CPDFSDK_Annot* pAnnot, FX_BOOL bRegister);
 	void						RemoveFormFiller(CPDFSDK_Annot* pAnnot);
 
@@ -96,12 +92,15 @@
 	void						OnButtonUp(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bReset, FX_BOOL& bExit,FX_UINT nFlag);
 
 private:
-	void						UnRegisterFormFiller(CPDFSDK_Annot* pAnnot);
-	void						SetFocusAnnotTab(CPDFSDK_Annot* pWidget, FX_BOOL bSameField, FX_BOOL bNext);
+    using CFFL_Widget2Filler = std::map<CPDFSDK_Annot*, CFFL_FormFiller*>;
 
-	CPDFDoc_Environment*				m_pApp;
-	CFFL_Widget2Filler			m_Maps;
-	FX_BOOL						m_bNotifying;
+    void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot);
+    void SetFocusAnnotTab(CPDFSDK_Annot* pWidget, FX_BOOL bSameField,
+                          FX_BOOL bNext);
+
+    CPDFDoc_Environment* m_pApp;
+    CFFL_Widget2Filler m_Maps;
+    FX_BOOL m_bNotifying;
 };
 
 class CFFL_PrivateData
diff --git a/fpdfsdk/include/formfiller/FFL_ListBox.h b/fpdfsdk/include/formfiller/FFL_ListBox.h
index 81abec1..4c0813f 100644
--- a/fpdfsdk/include/formfiller/FFL_ListBox.h
+++ b/fpdfsdk/include/formfiller/FFL_ListBox.h
@@ -7,6 +7,8 @@
 #ifndef FPDFSDK_INCLUDE_FORMFILLER_FFL_LISTBOX_H_
 #define FPDFSDK_INCLUDE_FORMFILLER_FFL_LISTBOX_H_
 
+#include <set>
+
 #include "FFL_FormFiller.h"
 
 class  CBA_FontMap;
@@ -14,32 +16,37 @@
 class CFFL_ListBox : public CFFL_FormFiller
 {
 public:
-	CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget);
-	virtual ~CFFL_ListBox();
+    CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget);
+    virtual ~CFFL_ListBox();
 
-	virtual	PWL_CREATEPARAM		GetCreateParam();
-	virtual CPWL_Wnd*			NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView);
+    virtual PWL_CREATEPARAM GetCreateParam();
+    virtual CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp,
+                                   CPDFSDK_PageView* pPageView);
 
-	virtual FX_BOOL				OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags);
+    virtual FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar,
+                           FX_UINT nFlags);
 
-	virtual FX_BOOL				IsDataChanged(CPDFSDK_PageView* pPageView);
-	virtual void				SaveData(CPDFSDK_PageView* pPageView);
+    virtual FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView);
+    virtual void SaveData(CPDFSDK_PageView* pPageView);
 
- 	virtual void				GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
- 									PDFSDK_FieldAction& fa);
- 	virtual void				SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type,
- 									const PDFSDK_FieldAction& fa);
+    virtual void GetActionData(CPDFSDK_PageView* pPageView,
+                               CPDF_AAction::AActionType type,
+                               PDFSDK_FieldAction& fa);
+    virtual void SetActionData(CPDFSDK_PageView* pPageView,
+                               CPDF_AAction::AActionType type,
+                               const PDFSDK_FieldAction& fa);
 
-	virtual void				SaveState(CPDFSDK_PageView* pPageView);
-	virtual void				RestoreState(CPDFSDK_PageView* pPageView);
+    virtual void SaveState(CPDFSDK_PageView* pPageView);
+    virtual void RestoreState(CPDFSDK_PageView* pPageView);
 
-	virtual CPWL_Wnd*			ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue);
-	virtual void				OnKeyStroke(FX_BOOL bKeyDown, FX_DWORD nFlag);
+    virtual CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView,
+                                     FX_BOOL bRestoreValue);
+    virtual void OnKeyStroke(FX_BOOL bKeyDown, FX_DWORD nFlag);
 
 private:
-	CBA_FontMap*					m_pFontMap;
-	CFX_MapPtrTemplate<int, void*>	m_OriginSelections;
-	CFX_ArrayTemplate<int>			m_State;
+    CBA_FontMap* m_pFontMap;
+    std::set<int> m_OriginSelections;
+    CFX_ArrayTemplate<int> m_State;
 };
 
 
diff --git a/fpdfsdk/include/fsdk_annothandler.h b/fpdfsdk/include/fsdk_annothandler.h
index 521c46e..b470569 100644
--- a/fpdfsdk/include/fsdk_annothandler.h
+++ b/fpdfsdk/include/fsdk_annothandler.h
@@ -219,8 +219,6 @@
 	CPDFDoc_Environment*		m_pApp;
 };
 
-//#define CBF_Page2Accessible	 CFX_MapPtrTemplate<CPDFSDK_PageView*, IAccessible*>
-
 typedef int (*AI_COMPARE) (CPDFSDK_Annot* p1, CPDFSDK_Annot* p2);
 
 class CPDFSDK_AnnotIterator
diff --git a/fpdfsdk/include/fsdk_baseform.h b/fpdfsdk/include/fsdk_baseform.h
index 718ff60..edbd5e4 100644
--- a/fpdfsdk/include/fsdk_baseform.h
+++ b/fpdfsdk/include/fsdk_baseform.h
@@ -13,6 +13,8 @@
 #include <ctime>
 #endif
 
+#include <map>
+
 #include "../../core/include/fpdfapi/fpdf_parser.h"
 #include "../../core/include/fpdfdoc/fpdf_doc.h"
 #include "../../core/include/fxcrt/fx_basic.h"
@@ -165,8 +167,6 @@
 	int32_t						m_nValueAge;
 };
 
-#define CPDFSDK_WidgetMap				CFX_MapPtrTemplate<CPDF_FormControl*, CPDFSDK_Widget*>
-
 class CPDFSDK_InterForm : public CPDF_FormNotify
 {
 public:
@@ -201,7 +201,6 @@
 	void							ResetFieldAppearance(CPDF_FormField* pFormField, const FX_WCHAR* sValue, FX_BOOL bValueChanged);
 	void							UpdateField(CPDF_FormField* pFormField);
 
-public:
 	FX_BOOL							DoAction_Hide(const CPDF_Action& action);
 	FX_BOOL							DoAction_SubmitForm(const CPDF_Action& action);
 	FX_BOOL							DoAction_ResetForm(const CPDF_Action& action);
@@ -227,18 +226,18 @@
 	virtual int						BeforeFormImportData(const CPDF_InterForm* pForm);
 	virtual int						AfterFormImportData(const CPDF_InterForm* pForm);
 
-private:
 	FX_BOOL							FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile);
 	FX_BOOL							FDFToURLEncodedData(uint8_t*& pBuf, FX_STRSIZE& nBufSize);
 	int								GetPageIndexByAnnotDict(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict) const;
 	void							DoFDFBuffer(CFX_ByteString sBuffer);
 
-private:
-	CPDFSDK_Document*				m_pDocument;
-	CPDF_InterForm*					m_pInterForm;
-	CPDFSDK_WidgetMap				m_Map;
-	FX_BOOL							m_bCalculate;
-	FX_BOOL							m_bBusy;
+    using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>;
+
+    CPDFSDK_Document* m_pDocument;
+    CPDF_InterForm* m_pInterForm;
+    CPDFSDK_WidgetMap m_Map;
+    FX_BOOL m_bCalculate;
+    FX_BOOL m_bBusy;
 
 public:
 	FX_BOOL IsNeedHighLight(int nFieldType);
diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h
index 18092bb..43f6bf0 100644
--- a/fpdfsdk/include/fsdk_mgr.h
+++ b/fpdfsdk/include/fsdk_mgr.h
@@ -7,6 +7,8 @@
 #ifndef FPDFSDK_INCLUDE_FSDK_MGR_H_
 #define FPDFSDK_INCLUDE_FSDK_MGR_H_
 
+#include <map>
+
 #include "../../core/include/fpdftext/fpdf_text.h"
 #include "../../public/fpdf_formfill.h"
 #include "../../public/fpdf_fwlevent.h" // cross platform keycode and events define.
@@ -372,8 +374,6 @@
 	CPDFSDK_InterForm*		GetInterForm() ;
 	CPDF_Document*			GetDocument() {return m_pDoc;}
 
-	void					InitPageView();
-	void					AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView);
 	CPDFSDK_PageView*		GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew = TRUE);
 	CPDFSDK_PageView*		GetPageView(int nIndex);
 	CPDFSDK_PageView*		GetCurrentView();
@@ -406,13 +406,13 @@
 	FX_BOOL					ProcOpenAction();
 	CPDF_OCContext*			GetOCContext();
 private:
-	CFX_MapPtrTemplate<CPDF_Page*, CPDFSDK_PageView*> m_pageMap;
-	CPDF_Document*			m_pDoc;
-	CPDFSDK_InterForm*		m_pInterForm;
-	CPDFSDK_Annot*			m_pFocusAnnot;
-	CPDFDoc_Environment *	m_pEnv;
-	CPDF_OCContext *		m_pOccontent;
-	FX_BOOL					m_bChangeMask;
+    std::map<CPDF_Page*, CPDFSDK_PageView*> m_pageMap;
+    CPDF_Document* m_pDoc;
+    CPDFSDK_InterForm* m_pInterForm;
+    CPDFSDK_Annot* m_pFocusAnnot;
+    CPDFDoc_Environment* m_pEnv;
+    CPDF_OCContext* m_pOccontent;
+    FX_BOOL m_bChangeMask;
 };
 class CPDFSDK_PageView final
 {
diff --git a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
index 7f5ee2f..6b211f3 100644
--- a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
+++ b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
@@ -28,23 +28,14 @@
 
 CFFL_FormFiller::~CFFL_FormFiller()
 {
-	FX_POSITION pos = m_Maps.GetStartPosition();
-	while (pos)
-	{
-		CPDFSDK_PageView * pPageView = NULL;
-		CPWL_Wnd* pWnd = NULL;
-		m_Maps.GetNextAssoc(pos, pPageView, pWnd);
-
-		if (pWnd)
-		{
-			CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
-			pWnd->Destroy();
-			delete pWnd;
-			delete pData;
-		}
-	}
-	m_Maps.RemoveAll();
-
+    for (auto& it : m_Maps) {
+        CPWL_Wnd* pWnd = it.second;
+        CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
+        pWnd->Destroy();
+        delete pWnd;
+        delete pData;
+    }
+    m_Maps.clear();
 }
 
 void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, const CPDF_Rect& rcWindow)
@@ -430,64 +421,53 @@
 
 CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew)
 {
-	ASSERT(pPageView != NULL);
-	ASSERT(m_pWidget != NULL);
+    ASSERT(pPageView);
 
-	CPWL_Wnd* pWnd = NULL;
-	m_Maps.Lookup(pPageView, pWnd);
+    auto it = m_Maps.find(pPageView);
+    const bool found = it != m_Maps.end();
+    CPWL_Wnd* pWnd = found ? it->second : nullptr;
+    if (!bNew)
+        return pWnd;
 
-	if (bNew)
-	{
-		if (pWnd)
-		{
-			CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pWnd->GetAttachedData();
-			ASSERT(pPrivateData != NULL);
+    if (found) {
+        CFFL_PrivateData* pPrivateData =
+            (CFFL_PrivateData*)pWnd->GetAttachedData();
+        if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge()) {
+            return ResetPDFWindow(
+                pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge);
+      }
+    } else {
+      PWL_CREATEPARAM cp = GetCreateParam();
+      cp.hAttachedWnd = (FX_HWND)m_pWidget;
 
-			if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge())
-			{
-				return ResetPDFWindow(pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge);
-			}
-		}
-		else
-		{
-			PWL_CREATEPARAM cp = GetCreateParam();
-			cp.hAttachedWnd = (FX_HWND)m_pWidget;
+      CFFL_PrivateData* pPrivateData = new CFFL_PrivateData;
+      pPrivateData->pWidget = m_pWidget;
+      pPrivateData->pPageView = pPageView;
+      pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge();
+      pPrivateData->nValueAge = 0;
 
-			CFFL_PrivateData* pPrivateData = new CFFL_PrivateData;
-			pPrivateData->pWidget = m_pWidget;
-			pPrivateData->pPageView = pPageView;
-			pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge();
-                        pPrivateData->nValueAge = 0;
+      cp.pAttachedData = pPrivateData;
 
-			cp.pAttachedData = pPrivateData;
+      pWnd = NewPDFWindow(cp, pPageView);
+      m_Maps[pPageView] = pWnd;
+    }
 
-			pWnd = NewPDFWindow(cp, pPageView);
-
-			if (pWnd)
-			{
-				m_Maps.SetAt(pPageView, pWnd);
-			}
-		}
-	}
-
-	return pWnd;
+    return pWnd;
 }
 
 void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView)
 {
-	CPWL_Wnd* pWnd = NULL;
-	m_Maps.Lookup(pPageView, pWnd);
+    auto it = m_Maps.find(pPageView);
+    if (it == m_Maps.end())
+        return;
 
-	if (pWnd)
-	{
-		CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
-		pData->pPageView = NULL;
-		pWnd->Destroy();
-		delete pWnd;
-		delete pData;
-	}
+    CPWL_Wnd* pWnd = it->second;
+    CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
+    pWnd->Destroy();
+    delete pWnd;
+    delete pData;
 
-	m_Maps.RemoveKey(pPageView);
+    m_Maps.erase(it);
 }
 
 CPDF_Matrix	CFFL_FormFiller::GetWindowMatrix(void* pAttachedData)
diff --git a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
index 464ff3c..62090a5 100644
--- a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
+++ b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
@@ -28,15 +28,9 @@
 
 CFFL_IFormFiller::~CFFL_IFormFiller()
 {
-	FX_POSITION pos = m_Maps.GetStartPosition();
-	while (pos)
-	{
-		CPDFSDK_Annot * pAnnot = NULL;
-		CFFL_FormFiller * pFormFiller = NULL;
-		m_Maps.GetNextAssoc(pos,pAnnot,pFormFiller);
-		delete pFormFiller;
-	}
-	m_Maps.RemoveAll();
+    for (auto& it : m_Maps)
+        delete it.second;
+    m_Maps.clear();
 }
 
 FX_BOOL	CFFL_IFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView,CPDFSDK_Annot* pAnnot, CPDF_Point point)
@@ -645,53 +639,46 @@
 
 CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot, FX_BOOL bRegister)
 {
-// 	ASSERT(pAnnot != NULL);
-// 	ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget");
+    auto it = m_Maps.find(pAnnot);
+    if (it != m_Maps.end())
+        return it->second;
 
-	CFFL_FormFiller * pFormFiller = NULL;
-	m_Maps.Lookup(pAnnot, pFormFiller);
+    if (!bRegister)
+        return nullptr;
 
-	if (pFormFiller)
-		return pFormFiller;
+    CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+    int nFieldType = pWidget->GetFieldType();
+    CFFL_FormFiller* pFormFiller;
+    switch (nFieldType) {
+        case FIELDTYPE_PUSHBUTTON:
+            pFormFiller = new CFFL_PushButton(m_pApp, pWidget);
+            break;
+        case FIELDTYPE_CHECKBOX:
+            pFormFiller = new CFFL_CheckBox(m_pApp, pWidget);
+            break;
+      case FIELDTYPE_RADIOBUTTON:
+            pFormFiller = new CFFL_RadioButton(m_pApp, pWidget);
+            break;
+      case FIELDTYPE_TEXTFIELD:
+            pFormFiller = new CFFL_TextField(m_pApp, pWidget);
+            break;
+      case FIELDTYPE_LISTBOX:
+            pFormFiller = new CFFL_ListBox(m_pApp, pWidget);
+            break;
+      case FIELDTYPE_COMBOBOX:
+            pFormFiller = new CFFL_ComboBox(m_pApp, pWidget);
+            break;
+      case FIELDTYPE_UNKNOWN:
+      default:
+            pFormFiller = nullptr;
+            break;
+    }
 
-	if (bRegister)
-	{
-		CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
+    if (!pFormFiller)
+        return nullptr;
 
-		int nFieldType = pWidget->GetFieldType();
-		switch(nFieldType)
-		{
- 		case FIELDTYPE_PUSHBUTTON:
- 			pFormFiller = new CFFL_PushButton(m_pApp, pWidget);
- 			break;
-		case FIELDTYPE_CHECKBOX:
-			pFormFiller = new CFFL_CheckBox(m_pApp, pWidget);
-			break;
- 		case FIELDTYPE_RADIOBUTTON:
- 			pFormFiller = new CFFL_RadioButton(m_pApp, pWidget);
- 			break;
- 		case FIELDTYPE_TEXTFIELD:
-			pFormFiller = new CFFL_TextField(m_pApp, pWidget);
-			break;
-		case FIELDTYPE_LISTBOX:
-			pFormFiller = new CFFL_ListBox(m_pApp, pWidget);
-			break;
-		case FIELDTYPE_COMBOBOX:
-			pFormFiller = new CFFL_ComboBox(m_pApp, pWidget);
-			break;
-		case FIELDTYPE_UNKNOWN:
-		default:
-			pFormFiller = NULL;
-			break;
-		}
-
-		if (pFormFiller)
-		{
-			m_Maps.SetAt(pAnnot, pFormFiller);
-		}
-	}
-
-	return pFormFiller;
+    m_Maps[pAnnot] = pFormFiller;
+    return pFormFiller;
 }
 
 void CFFL_IFormFiller::RemoveFormFiller(CPDFSDK_Annot* pAnnot)
@@ -704,11 +691,12 @@
 
 void CFFL_IFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot)
 {
-    CFFL_FormFiller* pFormFiller = nullptr;
-    if (m_Maps.Lookup(pAnnot,pFormFiller)) {
-        delete pFormFiller;
-        m_Maps.RemoveKey(pAnnot);
-    }
+    auto it = m_Maps.find(pAnnot);
+    if (it == m_Maps.end())
+        return;
+
+    delete it->second;
+    m_Maps.erase(it);
 }
 
 void CFFL_IFormFiller::SetFocusAnnotTab(CPDFSDK_Annot* pWidget, FX_BOOL bSameField, FX_BOOL bNext)
diff --git a/fpdfsdk/src/formfiller/FFL_ListBox.cpp b/fpdfsdk/src/formfiller/FFL_ListBox.cpp
index 4622d4f..28dcf34 100644
--- a/fpdfsdk/src/formfiller/FFL_ListBox.cpp
+++ b/fpdfsdk/src/formfiller/FFL_ListBox.cpp
@@ -75,7 +75,7 @@
 
 	if (pWnd->HasFlag(PLBS_MULTIPLESEL))
 	{
-		m_OriginSelections.RemoveAll();
+		m_OriginSelections.clear();
 
 		FX_BOOL bSetCaret = FALSE;
 		for (int32_t i=0,sz=m_pWidget->CountOptions(); i<sz; i++)
@@ -88,7 +88,7 @@
 					bSetCaret = TRUE;
 				}
 				pWnd->Select(i);
-				m_OriginSelections.SetAt(i, NULL);
+				m_OriginSelections.insert(i);
 			}
 		}
 	}
@@ -115,36 +115,26 @@
 	return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
 }
 
-FX_BOOL	CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView)
+FX_BOOL CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView)
 {
-	ASSERT(m_pWidget != NULL);
+    CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE);
+    if (!pListBox)
+        return FALSE;
 
-	if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE))
-	{
-		if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT)
-		{
-			int nSelCount = 0;
-			for (int32_t i=0,sz=pListBox->GetCount(); i<sz; i++)
-			{
-				if (pListBox->IsItemSelected(i))
-				{
-					void* p = NULL;
-					if (!m_OriginSelections.Lookup(i, p))
-						return TRUE;
+    if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) {
+        int nSelCount = 0;
+        for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; ++i) {
+            if (pListBox->IsItemSelected(i)) {
+                if (m_OriginSelections.count(i) == 0)
+                    return TRUE;
 
-					nSelCount++;
-				}
-			}
+                nSelCount++;
+            }
+        }
 
-			return nSelCount != m_OriginSelections.GetCount();
-		}
-		else
-		{
-			return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0);
-		}
-	}
-
-	return FALSE;
+        return nSelCount != m_OriginSelections.size();
+    }
+    return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0);
 }
 
 void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView)
diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp
index a8dfe7f..9358c9e 100644
--- a/fpdfsdk/src/fpdfformfill.cpp
+++ b/fpdfsdk/src/fpdfformfill.cpp
@@ -339,7 +339,6 @@
 		return;
 	if( CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc())
 	{
-		pSDKDoc->InitPageView();
 		if(((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
 			pSDKDoc->ProcJavascriptFun();
 	}
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index 312d323..d374252 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -1666,10 +1666,9 @@
 
 CPDFSDK_InterForm::~CPDFSDK_InterForm()
 {
-	delete m_pInterForm;
-	m_pInterForm = NULL;
-
-	m_Map.RemoveAll();
+    delete m_pInterForm;
+    m_pInterForm = nullptr;
+    m_Map.clear();
 }
 
 FX_BOOL CPDFSDK_InterForm::HighlightWidgets()
@@ -1688,45 +1687,40 @@
     return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);
 }
 
-CPDFSDK_Widget*	CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const
+CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const
 {
-	if(!pControl || !m_pInterForm) return NULL;
+    if (!pControl || !m_pInterForm)
+        return nullptr;
 
-	CPDFSDK_Widget* pWidget = NULL;
-	m_Map.Lookup(pControl, pWidget);
+    CPDFSDK_Widget* pWidget = nullptr;
+    const auto it = m_Map.find(pControl);
+    if (it != m_Map.end())
+        pWidget = it->second;
 
-	if (pWidget) return pWidget;
+    if (pWidget)
+        return pWidget;
 
-	CPDF_Dictionary* pControlDict = pControl->GetWidget();
-	ASSERT(pControlDict != NULL);
+    CPDF_Dictionary* pControlDict = pControl->GetWidget();
+    CPDF_Document* pDocument = m_pDocument->GetDocument();
+    CPDFSDK_PageView* pPage = nullptr;
 
-	ASSERT(m_pDocument != NULL);
-	CPDF_Document* pDocument = m_pDocument->GetDocument();
+    if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P")) {
+        int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
+        if (nPageIndex >= 0) {
+            pPage = m_pDocument->GetPageView(nPageIndex);
+      }
+    }
 
-	CPDFSDK_PageView* pPage = NULL;
+    if (!pPage) {
+        int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);
+        if (nPageIndex >= 0) {
+            pPage = m_pDocument->GetPageView(nPageIndex);
+        }
+    }
 
-	if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P"))
-	{
-		int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
-		if (nPageIndex >= 0)
-		{
-			pPage = m_pDocument->GetPageView(nPageIndex);
-		}
-	}
-
-	if (!pPage)
-	{
-		int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);
-		if (nPageIndex >= 0)
-		{
-			pPage = m_pDocument->GetPageView(nPageIndex);
-		}
-	}
-
-	if (pPage)
-		return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
-
-	return NULL;
+    if (!pPage)
+        return nullptr;
+    return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
 }
 
 void CPDFSDK_InterForm::GetWidgets(const CFX_WideString& sFieldName, CFX_PtrArray& widgets)
@@ -1786,12 +1780,12 @@
 
 void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget)
 {
-	m_Map.SetAt(pControl, pWidget);
+    m_Map[pControl] = pWidget;
 }
 
 void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl)
 {
-	m_Map.RemoveKey(pControl);
+    m_Map.erase(pControl);
 }
 
 void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled)
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index 5d4680d..0037532 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -317,14 +317,9 @@
 
 CPDFSDK_Document::~CPDFSDK_Document()
 {
-    FX_POSITION pos = m_pageMap.GetStartPosition();
-    while (pos) {
-        CPDF_Page* pPage = NULL;
-        CPDFSDK_PageView* pPageView = NULL;
-        m_pageMap.GetNextAssoc(pos, pPage, pPageView);
-        delete pPageView;
-    }
-    m_pageMap.RemoveAll();
+    for (auto& it : m_pageMap)
+        delete it.second;
+    m_pageMap.clear();
 
     delete m_pInterForm;
     m_pInterForm = nullptr;
@@ -333,36 +328,20 @@
     m_pOccontent = nullptr;
 }
 
-void CPDFSDK_Document::InitPageView()
-{
-	int nCount = m_pDoc->GetPageCount();
-	for(int i=0; i<nCount; i++)
-	{
-	// To do
-//		CPDF_Dictionary* pDic = m_pDoc->GetPage(i);
-//		m_pageMap.SetAt(pDic, pPageView);
-	}
-}
-
-void CPDFSDK_Document::AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView)
-{
-	m_pageMap.SetAt(pPDFPage, pPageView);
-}
-
 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew)
 {
-	CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);
-	if(pPageView != NULL)
-		return pPageView;
-	if(ReNew)
-	{
-		pPageView = new CPDFSDK_PageView(this,pPDFPage);
-		m_pageMap.SetAt(pPDFPage, pPageView);
-		//Delay to load all the annotations, to avoid endless loop.
-		pPageView->LoadFXAnnots();
-	}
-	return pPageView;
+    auto it = m_pageMap.find(pPDFPage);
+    if (it != m_pageMap.end())
+        return it->second;
 
+    if (!ReNew)
+        return nullptr;
+
+    CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pPDFPage);
+    m_pageMap[pPDFPage] = pPageView;
+    // Delay to load all the annotations, to avoid endless loop.
+    pPageView->LoadFXAnnots();
+    return pPageView;
 }
 
 CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
@@ -373,16 +352,12 @@
 
 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
 {
-	CPDFSDK_PageView * pTempPageView = NULL;
-	CPDF_Page * pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
-	if(!pTempPage)
-		return NULL;
+    CPDF_Page* pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex);
+    if (!pTempPage)
+        return nullptr;
 
-	m_pageMap.Lookup(pTempPage, pTempPageView);
-
-	ASSERT(pTempPageView != NULL);
-
-	return pTempPageView;
+    auto it = m_pageMap.find(pTempPage);
+    return it->second;
 }
 
 void CPDFSDK_Document:: ProcJavascriptFun()
@@ -440,12 +415,16 @@
 
 void CPDFSDK_Document::ReMovePageView(CPDF_Page* pPDFPage)
 {
-	CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);
-	if(pPageView && !pPageView->IsLocked())
-	{
-		delete pPageView;
-		m_pageMap.RemoveKey(pPDFPage);
-	}
+    auto it = m_pageMap.find(pPDFPage);
+    if (it == m_pageMap.end())
+        return;
+
+    CPDFSDK_PageView* pPageView = it->second;
+    if (pPageView->IsLocked())
+        return;
+
+    delete pPageView;
+    m_pageMap.erase(it);
 }
 
 CPDF_Page * CPDFSDK_Document::GetPage(int nIndex)
@@ -465,19 +444,12 @@
 
 void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
 {
-
-	FX_POSITION pos = m_pageMap.GetStartPosition();
-	CPDF_Page * pPage = NULL;
-	CPDFSDK_PageView * pPageView = NULL;
-	while(pos)
-	{
-		m_pageMap.GetNextAssoc(pos, pPage, pPageView);
-
-		if(pPageView != pSender)
-		{
-			pPageView->UpdateView(pAnnot);
-		}
-	}
+    for (const auto& it : m_pageMap) {
+        CPDFSDK_PageView* pPageView = it.second;
+        if (pPageView != pSender) {
+            pPageView->UpdateView(pAnnot);
+        }
+    }
 }
 
 CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
diff --git a/fpdfsdk/src/pdfwindow/PWL_Wnd.cpp b/fpdfsdk/src/pdfwindow/PWL_Wnd.cpp
index dcc6e40..89d4bab 100644
--- a/fpdfsdk/src/pdfwindow/PWL_Wnd.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_Wnd.cpp
@@ -4,6 +4,8 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#include <map>
+
 #include "../../include/pdfwindow/PDFWindow.h"
 #include "../../include/pdfwindow/PWL_Wnd.h"
 #include "../../include/pdfwindow/PWL_Utils.h"
@@ -11,10 +13,10 @@
 
 /* -------------------------- CPWL_Timer -------------------------- */
 
-static CFX_MapPtrTemplate<int32_t, CPWL_Timer*>& GetPWLTimeMap()
+static std::map<int32_t, CPWL_Timer*>& GetPWLTimeMap()
 {
   // Leak the object at shutdown.
-  static auto timeMap = new CFX_MapPtrTemplate<int32_t, CPWL_Timer*>;
+  static auto timeMap = new std::map<int32_t, CPWL_Timer*>;
   return *timeMap;
 }
 
@@ -34,33 +36,33 @@
 
 int32_t CPWL_Timer::SetPWLTimer(int32_t nElapse)
 {
-	if (m_nTimerID != 0) KillPWLTimer();
-	m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc);
-	GetPWLTimeMap().SetAt(m_nTimerID, this);
-	return m_nTimerID;
+    if (m_nTimerID != 0)
+        KillPWLTimer();
+    m_nTimerID = m_pSystemHandler->SetTimer(nElapse, TimerProc);
+
+    GetPWLTimeMap()[m_nTimerID] = this;
+    return m_nTimerID;
 }
 
 void CPWL_Timer::KillPWLTimer()
 {
-	if (m_nTimerID != 0)
-	{
-		m_pSystemHandler->KillTimer(m_nTimerID);
-		GetPWLTimeMap().RemoveKey(m_nTimerID);
-		m_nTimerID = 0;
-	}
+    if (m_nTimerID == 0)
+        return;
+
+    m_pSystemHandler->KillTimer(m_nTimerID);
+    GetPWLTimeMap().erase(m_nTimerID);
+    m_nTimerID = 0;
 }
 
 void CPWL_Timer::TimerProc(int32_t idEvent)
 {
-	CPWL_Timer* pTimer = NULL;
-	if (GetPWLTimeMap().Lookup(idEvent, pTimer))
-	{
-		if (pTimer)
-		{
-			if (pTimer->m_pAttached)
-				pTimer->m_pAttached->TimerProc();
-		}
-	}
+    auto it = GetPWLTimeMap().find(idEvent);
+    if (it == GetPWLTimeMap().end())
+        return;
+
+    CPWL_Timer* pTimer = it->second;
+    if (pTimer->m_pAttached)
+        pTimer->m_pAttached->TimerProc();
 }
 
 /* -------------------------- CPWL_TimerHandler -------------------------- */