Remove CFX_MapPtrToPtr and templates.

All usage is now replaced with stl equivalents.
Move one definition from fx_basic.h to where it's actually needed.

Review-Url: https://codereview.chromium.org/2612773007
diff --git a/BUILD.gn b/BUILD.gn
index b462761..53236f5 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -730,7 +730,6 @@
     "core/fxcrt/fx_basic_coords.cpp",
     "core/fxcrt/fx_basic_gcc.cpp",
     "core/fxcrt/fx_basic_memmgr.cpp",
-    "core/fxcrt/fx_basic_plex.cpp",
     "core/fxcrt/fx_basic_utf.cpp",
     "core/fxcrt/fx_basic_util.cpp",
     "core/fxcrt/fx_basic_wstring.cpp",
@@ -755,7 +754,6 @@
     "core/fxcrt/fxcrt_stream.cpp",
     "core/fxcrt/fxcrt_windows.cpp",
     "core/fxcrt/fxcrt_windows.h",
-    "core/fxcrt/plex.h",
     "core/fxcrt/xml_int.h",
   ]
   configs += [ ":pdfium_core_config" ]
@@ -772,7 +770,6 @@
       "core/fxcrt/fx_arabic.cpp",
       "core/fxcrt/fx_arabic.h",
       "core/fxcrt/fx_arb.h",
-      "core/fxcrt/fx_basic_maps.cpp",
     ]
   }
 }
diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h
index 3b09489..5adcf70 100644
--- a/core/fxcrt/fx_basic.h
+++ b/core/fxcrt/fx_basic.h
@@ -335,108 +335,6 @@
   std::unique_ptr<DataType, FxFreeDeleter> m_pGrowData;
 };
 
-#ifdef PDF_ENABLE_XFA
-class CFX_MapPtrToPtr {
- protected:
-  struct CAssoc {
-    CAssoc* pNext;
-    void* key;
-    void* value;
-  };
-
- public:
-  explicit CFX_MapPtrToPtr(int nBlockSize = 10);
-  ~CFX_MapPtrToPtr();
-
-  int GetCount() const { return m_nCount; }
-  bool IsEmpty() const { return m_nCount == 0; }
-
-  bool Lookup(void* key, void*& rValue) const;
-
-  void* GetValueAt(void* key) const;
-
-  void*& operator[](void* key);
-
-  void SetAt(void* key, void* newValue) { (*this)[key] = newValue; }
-
-  bool RemoveKey(void* key);
-
-  void RemoveAll();
-
-  FX_POSITION GetStartPosition() const {
-    return m_nCount == 0 ? nullptr : (FX_POSITION)-1;
-  }
-
-  void GetNextAssoc(FX_POSITION& rNextPosition,
-                    void*& rKey,
-                    void*& rValue) const;
-
-  uint32_t GetHashTableSize() const { return m_nHashTableSize; }
-
-  void InitHashTable(uint32_t hashSize, bool bAllocNow = true);
-
- protected:
-  CAssoc** m_pHashTable;
-
-  uint32_t m_nHashTableSize;
-
-  int m_nCount;
-
-  CAssoc* m_pFreeList;
-
-  struct CFX_Plex* m_pBlocks;
-
-  int m_nBlockSize;
-
-  uint32_t HashKey(void* key) const;
-
-  CAssoc* NewAssoc();
-
-  void FreeAssoc(CAssoc* pAssoc);
-
-  CAssoc* GetAssocAt(void* key, uint32_t& hash) const;
-};
-
-template <class KeyType, class ValueType>
-class CFX_MapPtrTemplate : public CFX_MapPtrToPtr {
- public:
-  CFX_MapPtrTemplate() : CFX_MapPtrToPtr(10) {}
-
-  bool Lookup(KeyType key, ValueType& rValue) const {
-    void* pValue = nullptr;
-    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);
-  }
-
-  bool RemoveKey(KeyType key) {
-    return CFX_MapPtrToPtr::RemoveKey((void*)(uintptr_t)key);
-  }
-
-  void GetNextAssoc(FX_POSITION& rNextPosition,
-                    KeyType& rKey,
-                    ValueType& rValue) const {
-    void* pKey = nullptr;
-    void* pValue = nullptr;
-    CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue);
-    rKey = (KeyType)(uintptr_t)pKey;
-    rValue = (ValueType)(uintptr_t)pValue;
-  }
-};
-
-typedef void (*PD_CALLBACK_FREEDATA)(void* pData);
-#endif  // PDF_ENABLE_XFA
-
 class CFX_BitStream {
  public:
   void Init(const uint8_t* pData, uint32_t dwSize);
diff --git a/core/fxcrt/fx_basic_maps.cpp b/core/fxcrt/fx_basic_maps.cpp
deleted file mode 100644
index 149951a..0000000
--- a/core/fxcrt/fx_basic_maps.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/fxcrt/fx_basic.h"
-#include "core/fxcrt/plex.h"
-
-CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize)
-    : m_pHashTable(nullptr),
-      m_nHashTableSize(17),
-      m_nCount(0),
-      m_pFreeList(nullptr),
-      m_pBlocks(nullptr),
-      m_nBlockSize(nBlockSize) {
-  ASSERT(m_nBlockSize > 0);
-}
-
-void CFX_MapPtrToPtr::RemoveAll() {
-  FX_Free(m_pHashTable);
-  m_pHashTable = nullptr;
-  m_nCount = 0;
-  m_pFreeList = nullptr;
-  if (m_pBlocks) {
-    m_pBlocks->FreeDataChain();
-    m_pBlocks = nullptr;
-  }
-}
-
-CFX_MapPtrToPtr::~CFX_MapPtrToPtr() {
-  RemoveAll();
-  ASSERT(m_nCount == 0);
-}
-uint32_t CFX_MapPtrToPtr::HashKey(void* key) const {
-  return ((uint32_t)(uintptr_t)key) >> 4;
-}
-void CFX_MapPtrToPtr::GetNextAssoc(FX_POSITION& rNextPosition,
-                                   void*& rKey,
-                                   void*& rValue) const {
-  ASSERT(m_pHashTable);
-  CAssoc* pAssocRet = (CAssoc*)rNextPosition;
-  ASSERT(pAssocRet);
-  if (pAssocRet == (CAssoc*)-1) {
-    for (uint32_t nBucket = 0; nBucket < m_nHashTableSize; nBucket++) {
-      pAssocRet = m_pHashTable[nBucket];
-      if (pAssocRet)
-        break;
-    }
-    ASSERT(pAssocRet);
-  }
-  CAssoc* pAssocNext = pAssocRet->pNext;
-  for (uint32_t nBucket = (HashKey(pAssocRet->key) % m_nHashTableSize) + 1;
-       nBucket < m_nHashTableSize && !pAssocNext; nBucket++) {
-    pAssocNext = m_pHashTable[nBucket];
-  }
-  rNextPosition = (FX_POSITION)pAssocNext;
-  rKey = pAssocRet->key;
-  rValue = pAssocRet->value;
-}
-bool CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const {
-  uint32_t nHash;
-  CAssoc* pAssoc = GetAssocAt(key, nHash);
-  if (!pAssoc) {
-    return false;
-  }
-  rValue = pAssoc->value;
-  return true;
-}
-
-void* CFX_MapPtrToPtr::GetValueAt(void* key) const {
-  uint32_t nHash;
-  CAssoc* pAssoc = GetAssocAt(key, nHash);
-  return pAssoc ? pAssoc->value : nullptr;
-}
-
-void*& CFX_MapPtrToPtr::operator[](void* key) {
-  uint32_t nHash;
-  CAssoc* pAssoc = GetAssocAt(key, nHash);
-  if (!pAssoc) {
-    if (!m_pHashTable)
-      InitHashTable(m_nHashTableSize);
-    pAssoc = NewAssoc();
-    pAssoc->key = key;
-    pAssoc->pNext = m_pHashTable[nHash];
-    m_pHashTable[nHash] = pAssoc;
-  }
-  return pAssoc->value;
-}
-CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::GetAssocAt(void* key,
-                                                     uint32_t& nHash) const {
-  nHash = HashKey(key) % m_nHashTableSize;
-  if (!m_pHashTable) {
-    return nullptr;
-  }
-  CAssoc* pAssoc;
-  for (pAssoc = m_pHashTable[nHash]; pAssoc; pAssoc = pAssoc->pNext) {
-    if (pAssoc->key == key)
-      return pAssoc;
-  }
-  return nullptr;
-}
-CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::NewAssoc() {
-  if (!m_pFreeList) {
-    CFX_Plex* newBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize,
-                                          sizeof(CFX_MapPtrToPtr::CAssoc));
-    CFX_MapPtrToPtr::CAssoc* pAssoc =
-        (CFX_MapPtrToPtr::CAssoc*)newBlock->data();
-    pAssoc += m_nBlockSize - 1;
-    for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) {
-      pAssoc->pNext = m_pFreeList;
-      m_pFreeList = pAssoc;
-    }
-  }
-  CFX_MapPtrToPtr::CAssoc* pAssoc = m_pFreeList;
-  m_pFreeList = m_pFreeList->pNext;
-  m_nCount++;
-  ASSERT(m_nCount > 0);
-  pAssoc->key = 0;
-  pAssoc->value = 0;
-  return pAssoc;
-}
-void CFX_MapPtrToPtr::InitHashTable(uint32_t nHashSize, bool bAllocNow) {
-  ASSERT(m_nCount == 0);
-  ASSERT(nHashSize > 0);
-  FX_Free(m_pHashTable);
-  m_pHashTable = nullptr;
-  if (bAllocNow) {
-    m_pHashTable = FX_Alloc(CAssoc*, nHashSize);
-  }
-  m_nHashTableSize = nHashSize;
-}
-bool CFX_MapPtrToPtr::RemoveKey(void* key) {
-  if (!m_pHashTable) {
-    return false;
-  }
-  CAssoc** ppAssocPrev;
-  ppAssocPrev = &m_pHashTable[HashKey(key) % m_nHashTableSize];
-  CAssoc* pAssoc;
-  for (pAssoc = *ppAssocPrev; pAssoc; pAssoc = pAssoc->pNext) {
-    if (pAssoc->key == key) {
-      *ppAssocPrev = pAssoc->pNext;
-      FreeAssoc(pAssoc);
-      return true;
-    }
-    ppAssocPrev = &pAssoc->pNext;
-  }
-  return false;
-}
-void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) {
-  pAssoc->pNext = m_pFreeList;
-  m_pFreeList = pAssoc;
-  m_nCount--;
-  ASSERT(m_nCount >= 0);
-  if (m_nCount == 0) {
-    RemoveAll();
-  }
-}
diff --git a/core/fxcrt/fx_basic_plex.cpp b/core/fxcrt/fx_basic_plex.cpp
deleted file mode 100644
index cb6fde6..0000000
--- a/core/fxcrt/fx_basic_plex.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/fxcrt/fx_memory.h"
-#include "core/fxcrt/plex.h"
-
-CFX_Plex* CFX_Plex::Create(CFX_Plex*& pHead,
-                           uint32_t nMax,
-                           uint32_t cbElement) {
-  CFX_Plex* p =
-      (CFX_Plex*)FX_Alloc(uint8_t, sizeof(CFX_Plex) + nMax * cbElement);
-  p->pNext = pHead;
-  pHead = p;
-  return p;
-}
-void CFX_Plex::FreeDataChain() {
-  CFX_Plex* p = this;
-  while (p) {
-    CFX_Plex* old = p;
-    p = p->pNext;
-    FX_Free(old);
-  }
-}
diff --git a/core/fxcrt/plex.h b/core/fxcrt/plex.h
deleted file mode 100644
index 8d00ef5..0000000
--- a/core/fxcrt/plex.h
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FXCRT_PLEX_H_
-#define CORE_FXCRT_PLEX_H_
-
-#include "core/fxcrt/fx_system.h"
-
-struct CFX_Plex {
-  CFX_Plex* pNext;
-  void* data() { return this + 1; }
-  static CFX_Plex* Create(CFX_Plex*& head, uint32_t nMax, uint32_t cbElement);
-  void FreeDataChain();
-};
-
-#endif  // CORE_FXCRT_PLEX_H_
diff --git a/xfa/fxfa/parser/xfa_object.h b/xfa/fxfa/parser/xfa_object.h
index 8be19ec..cc11650 100644
--- a/xfa/fxfa/parser/xfa_object.h
+++ b/xfa/fxfa/parser/xfa_object.h
@@ -128,6 +128,8 @@
 using CXFA_NodeArray = CFX_ArrayTemplate<CXFA_Node*>;
 using CXFA_NodeStack = CFX_StackTemplate<CXFA_Node*>;
 using CXFA_NodeSet = std::unordered_set<CXFA_Node*>;
+
+typedef void (*PD_CALLBACK_FREEDATA)(void* pData);
 typedef void (*PD_CALLBACK_DUPLICATEDATA)(void*& pData);
 
 struct XFA_MAPDATABLOCKCALLBACKINFO {