Index: core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp |
diff --git a/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp b/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp |
index cc395a2e089d7634d99331844e59d74a0fac50bf..e47d053db55740e5d14eadb1254419b0a5f1a35c 100644 |
--- a/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp |
+++ b/core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp |
@@ -18,7 +18,7 @@ |
#include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" |
#include "third_party/base/stl_util.h" |
-CPDF_Dictionary::CPDF_Dictionary() {} |
+CPDF_Dictionary::CPDF_Dictionary(CFX_ByteStringPool* pPool) : m_pPool(pPool) {} |
CPDF_Dictionary::~CPDF_Dictionary() { |
// Mark the object as deleted so that it will not be deleted again |
@@ -60,7 +60,7 @@ CPDF_Object* CPDF_Dictionary::CloneNonCyclic( |
bool bDirect, |
std::set<const CPDF_Object*>* pVisited) const { |
pVisited->insert(this); |
- CPDF_Dictionary* pCopy = new CPDF_Dictionary(); |
+ CPDF_Dictionary* pCopy = new CPDF_Dictionary(m_pPool); |
for (const auto& it : *this) { |
CPDF_Object* value = it.second; |
if (!pdfium::ContainsKey(*pVisited, value)) { |
@@ -172,7 +172,7 @@ void CPDF_Dictionary::SetFor(const CFX_ByteString& key, CPDF_Object* pObj) { |
auto it = m_Map.find(key); |
if (it == m_Map.end()) { |
if (pObj) |
- m_Map.insert(std::make_pair(key, pObj)); |
+ m_Map.insert(std::make_pair(MaybeIntern(key), pObj)); |
return; |
} |
@@ -209,7 +209,7 @@ void CPDF_Dictionary::ReplaceKey(const CFX_ByteString& oldkey, |
new_it->second->Release(); |
new_it->second = old_it->second; |
} else { |
- m_Map.insert(std::make_pair(newkey, old_it->second)); |
+ m_Map.insert(std::make_pair(MaybeIntern(newkey), old_it->second)); |
} |
m_Map.erase(old_it); |
} |
@@ -220,12 +220,12 @@ void CPDF_Dictionary::SetIntegerFor(const CFX_ByteString& key, int i) { |
void CPDF_Dictionary::SetNameFor(const CFX_ByteString& key, |
const CFX_ByteString& name) { |
- SetFor(key, new CPDF_Name(name)); |
+ SetFor(key, new CPDF_Name(MaybeIntern(name))); |
} |
void CPDF_Dictionary::SetStringFor(const CFX_ByteString& key, |
const CFX_ByteString& str) { |
- SetFor(key, new CPDF_String(str, FALSE)); |
+ SetFor(key, new CPDF_String(MaybeIntern(str), FALSE)); |
} |
void CPDF_Dictionary::SetReferenceFor(const CFX_ByteString& key, |
@@ -263,3 +263,7 @@ void CPDF_Dictionary::SetMatrixFor(const CFX_ByteString& key, |
pArray->AddNumber(matrix.f); |
SetFor(key, pArray); |
} |
+ |
+CFX_ByteString CPDF_Dictionary::MaybeIntern(const CFX_ByteString& str) { |
+ return m_pPool ? m_pPool->Intern(str) : str; |
+} |