Get rid of CXML_AttrMap.

BUG=pdfium:541

Change-Id: Id401af00e4cffebb49e187bf3a445439ce8c1082
Reviewed-on: https://pdfium-review.googlesource.com/21074
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index ac86f80..80ceb42 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -862,8 +862,6 @@
     "core/fxcrt/widestring.h",
     "core/fxcrt/xml/cxml_attritem.cpp",
     "core/fxcrt/xml/cxml_attritem.h",
-    "core/fxcrt/xml/cxml_attrmap.cpp",
-    "core/fxcrt/xml/cxml_attrmap.h",
     "core/fxcrt/xml/cxml_content.cpp",
     "core/fxcrt/xml/cxml_content.h",
     "core/fxcrt/xml/cxml_databufacc.cpp",
diff --git a/core/fxcrt/xml/cxml_attrmap.cpp b/core/fxcrt/xml/cxml_attrmap.cpp
deleted file mode 100644
index 733bbea..0000000
--- a/core/fxcrt/xml/cxml_attrmap.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2017 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/xml/cxml_attrmap.h"
-
-#include "third_party/base/ptr_util.h"
-#include "third_party/base/stl_util.h"
-
-CXML_AttrMap::CXML_AttrMap() {}
-
-CXML_AttrMap::~CXML_AttrMap() {}
-
-const WideString* CXML_AttrMap::Lookup(const ByteString& space,
-                                       const ByteString& name) const {
-  if (!m_pMap)
-    return nullptr;
-
-  for (const auto& item : *m_pMap) {
-    if (item.Matches(space, name))
-      return &item.m_Value;
-  }
-  return nullptr;
-}
-
-void CXML_AttrMap::SetAt(const ByteString& space,
-                         const ByteString& name,
-                         const WideString& value) {
-  if (!m_pMap)
-    m_pMap = pdfium::MakeUnique<std::vector<CXML_AttrItem>>();
-
-  for (CXML_AttrItem& item : *m_pMap) {
-    if (item.Matches(space, name)) {
-      item.m_Value = value;
-      return;
-    }
-  }
-
-  m_pMap->push_back({space, name, WideString(value)});
-}
-
-int CXML_AttrMap::GetSize() const {
-  return m_pMap ? pdfium::CollectionSize<int>(*m_pMap) : 0;
-}
-
-CXML_AttrItem& CXML_AttrMap::GetAt(int index) const {
-  return (*m_pMap)[index];
-}
diff --git a/core/fxcrt/xml/cxml_attrmap.h b/core/fxcrt/xml/cxml_attrmap.h
deleted file mode 100644
index a09522b..0000000
--- a/core/fxcrt/xml/cxml_attrmap.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2017 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_XML_CXML_ATTRMAP_H_
-#define CORE_FXCRT_XML_CXML_ATTRMAP_H_
-
-#include <memory>
-#include <vector>
-
-#include "core/fxcrt/fx_string.h"
-#include "core/fxcrt/xml/cxml_attritem.h"
-
-class CXML_AttrMap {
- public:
-  CXML_AttrMap();
-  ~CXML_AttrMap();
-
-  const WideString* Lookup(const ByteString& space,
-                           const ByteString& name) const;
-  int GetSize() const;
-  CXML_AttrItem& GetAt(int index) const;
-
-  void SetAt(const ByteString& space,
-             const ByteString& name,
-             const WideString& value);
-
-  std::unique_ptr<std::vector<CXML_AttrItem>> m_pMap;
-};
-
-#endif  // CORE_FXCRT_XML_CXML_ATTRMAP_H_
diff --git a/core/fxcrt/xml/cxml_element.cpp b/core/fxcrt/xml/cxml_element.cpp
index ad9859e..1d42e8e 100644
--- a/core/fxcrt/xml/cxml_element.cpp
+++ b/core/fxcrt/xml/cxml_element.cpp
@@ -61,9 +61,9 @@
   do {
     const WideString* pwsSpace;
     if (qName.IsEmpty())
-      pwsSpace = pElement->m_AttrMap.Lookup("", "xmlns");
+      pwsSpace = pElement->Lookup("", "xmlns");
     else
-      pwsSpace = pElement->m_AttrMap.Lookup("xmlns", qName);
+      pwsSpace = pElement->Lookup("xmlns", qName);
     if (pwsSpace)
       return pwsSpace->UTF8Encode();
 
@@ -76,10 +76,10 @@
                                   ByteString* space,
                                   ByteString* name,
                                   WideString* value) const {
-  if (index >= static_cast<size_t>(m_AttrMap.GetSize()))
+  if (index >= m_AttrMap.size())
     return;
 
-  CXML_AttrItem& item = m_AttrMap.GetAt(index);
+  const CXML_AttrItem& item = m_AttrMap[index];
   *space = item.m_QSpaceName;
   *name = item.m_AttrName;
   *value = item.m_Value;
@@ -91,8 +91,7 @@
   SplitQualifiedName(name, &bsSpace, &bsName);
 
   WideString attr;
-  const WideString* pValue =
-      m_AttrMap.Lookup(ByteString(bsSpace), ByteString(bsName));
+  const WideString* pValue = Lookup(ByteString(bsSpace), ByteString(bsName));
   if (pValue)
     attr = *pValue;
   return attr;
@@ -103,8 +102,7 @@
   ByteStringView bsName;
   SplitQualifiedName(name, &bsSpace, &bsName);
 
-  const WideString* pwsValue =
-      m_AttrMap.Lookup(ByteString(bsSpace), ByteString(bsName));
+  const WideString* pwsValue = Lookup(ByteString(bsSpace), ByteString(bsName));
   return pwsValue ? pwsValue->GetInteger() : 0;
 }
 
@@ -140,7 +138,13 @@
 void CXML_Element::SetAttribute(const ByteString& space,
                                 const ByteString& name,
                                 const WideString& value) {
-  m_AttrMap.SetAt(space, name, value);
+  for (CXML_AttrItem& item : m_AttrMap) {
+    if (item.Matches(space, name)) {
+      item.m_Value = value;
+      return;
+    }
+  }
+  m_AttrMap.push_back({space, name, WideString(value)});
 }
 
 // static
@@ -150,3 +154,12 @@
   return pKid && pKid->m_TagName == tag &&
          (space.IsEmpty() || pKid->m_QSpaceName == space);
 }
+
+const WideString* CXML_Element::Lookup(const ByteString& space,
+                                       const ByteString& name) const {
+  for (const CXML_AttrItem& item : m_AttrMap) {
+    if (item.Matches(space, name))
+      return &item.m_Value;
+  }
+  return nullptr;
+}
diff --git a/core/fxcrt/xml/cxml_element.h b/core/fxcrt/xml/cxml_element.h
index 038fa64..d3049d7 100644
--- a/core/fxcrt/xml/cxml_element.h
+++ b/core/fxcrt/xml/cxml_element.h
@@ -11,7 +11,7 @@
 #include <utility>
 #include <vector>
 
-#include "core/fxcrt/xml/cxml_attrmap.h"
+#include "core/fxcrt/xml/cxml_attritem.h"
 #include "core/fxcrt/xml/cxml_object.h"
 
 class CXML_Element : public CXML_Object {
@@ -30,7 +30,7 @@
   ByteString GetTagName() const;
   ByteString GetNamespaceURI(const ByteString& qName) const;
   const CXML_Element* GetParent() const { return m_pParent.Get(); }
-  size_t CountAttrs() const { return m_AttrMap.GetSize(); }
+  size_t CountAttrs() const { return m_AttrMap.size(); }
   void GetAttrByIndex(size_t index,
                       ByteString* space,
                       ByteString* name,
@@ -60,10 +60,13 @@
                              const ByteStringView& space,
                              const ByteStringView& tag);
 
+  const WideString* Lookup(const ByteString& space,
+                           const ByteString& name) const;
+
   UnownedPtr<const CXML_Element> const m_pParent;
-  ByteString m_QSpaceName;
-  ByteString m_TagName;
-  CXML_AttrMap m_AttrMap;
+  const ByteString m_QSpaceName;
+  const ByteString m_TagName;
+  std::vector<CXML_AttrItem> m_AttrMap;
   std::vector<std::unique_ptr<CXML_Object>> m_Children;
 };