Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_dictionary.cpp

Issue 2345063002: Use string pools in some dictionaries (Closed)
Patch Set: windows compile Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/fpdf_parser/cfdf_document.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_document.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
8 8
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
11 11
12 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h" 12 #include "core/fpdfapi/fpdf_parser/cpdf_boolean.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h"
15 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h"
16 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" 16 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
17 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" 17 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h"
18 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" 18 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
19 #include "third_party/base/stl_util.h" 19 #include "third_party/base/stl_util.h"
20 #include "third_party/base/logging.h" 20 #include "third_party/base/logging.h"
21 21
22 CPDF_Dictionary::CPDF_Dictionary() {} 22 CPDF_Dictionary::CPDF_Dictionary(const CFX_WeakPtr<CFX_ByteStringPool>& pPool)
23 : m_pPool(pPool) {}
23 24
24 CPDF_Dictionary::~CPDF_Dictionary() { 25 CPDF_Dictionary::~CPDF_Dictionary() {
25 // Mark the object as deleted so that it will not be deleted again 26 // Mark the object as deleted so that it will not be deleted again
26 // in case of cyclic references. 27 // in case of cyclic references.
27 m_ObjNum = kInvalidObjNum; 28 m_ObjNum = kInvalidObjNum;
28 for (const auto& it : m_Map) { 29 for (const auto& it : m_Map) {
29 if (it.second) 30 if (it.second)
30 it.second->Release(); 31 it.second->Release();
31 } 32 }
32 } 33 }
(...skipping 21 matching lines...) Expand all
54 } 55 }
55 56
56 CPDF_Object* CPDF_Dictionary::Clone() const { 57 CPDF_Object* CPDF_Dictionary::Clone() const {
57 return CloneObjectNonCyclic(false); 58 return CloneObjectNonCyclic(false);
58 } 59 }
59 60
60 CPDF_Object* CPDF_Dictionary::CloneNonCyclic( 61 CPDF_Object* CPDF_Dictionary::CloneNonCyclic(
61 bool bDirect, 62 bool bDirect,
62 std::set<const CPDF_Object*>* pVisited) const { 63 std::set<const CPDF_Object*>* pVisited) const {
63 pVisited->insert(this); 64 pVisited->insert(this);
64 CPDF_Dictionary* pCopy = new CPDF_Dictionary(); 65 CPDF_Dictionary* pCopy = new CPDF_Dictionary(m_pPool);
65 for (const auto& it : *this) { 66 for (const auto& it : *this) {
66 CPDF_Object* value = it.second; 67 CPDF_Object* value = it.second;
67 if (!pdfium::ContainsKey(*pVisited, value)) { 68 if (!pdfium::ContainsKey(*pVisited, value)) {
68 pCopy->m_Map.insert( 69 pCopy->m_Map.insert(
69 std::make_pair(it.first, value->CloneNonCyclic(bDirect, pVisited))); 70 std::make_pair(it.first, value->CloneNonCyclic(bDirect, pVisited)));
70 } 71 }
71 } 72 }
72 return pCopy; 73 return pCopy;
73 } 74 }
74 75
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 if (!pType) 168 if (!pType)
168 pType = GetDirectObjectFor("FT"); 169 pType = GetDirectObjectFor("FT");
169 return pType && pType->GetString() == "Sig"; 170 return pType && pType->GetString() == "Sig";
170 } 171 }
171 172
172 void CPDF_Dictionary::SetFor(const CFX_ByteString& key, CPDF_Object* pObj) { 173 void CPDF_Dictionary::SetFor(const CFX_ByteString& key, CPDF_Object* pObj) {
173 CHECK(!pObj || pObj->GetObjNum() == 0); 174 CHECK(!pObj || pObj->GetObjNum() == 0);
174 auto it = m_Map.find(key); 175 auto it = m_Map.find(key);
175 if (it == m_Map.end()) { 176 if (it == m_Map.end()) {
176 if (pObj) 177 if (pObj)
177 m_Map.insert(std::make_pair(key, pObj)); 178 m_Map.insert(std::make_pair(MaybeIntern(key), pObj));
178 return; 179 return;
179 } 180 }
180 181
181 if (it->second == pObj) 182 if (it->second == pObj)
182 return; 183 return;
183 it->second->Release(); 184 it->second->Release();
184 185
185 if (pObj) 186 if (pObj)
186 it->second = pObj; 187 it->second = pObj;
187 else 188 else
(...skipping 16 matching lines...) Expand all
204 return; 205 return;
205 206
206 auto new_it = m_Map.find(newkey); 207 auto new_it = m_Map.find(newkey);
207 if (new_it == old_it) 208 if (new_it == old_it)
208 return; 209 return;
209 210
210 if (new_it != m_Map.end()) { 211 if (new_it != m_Map.end()) {
211 new_it->second->Release(); 212 new_it->second->Release();
212 new_it->second = old_it->second; 213 new_it->second = old_it->second;
213 } else { 214 } else {
214 m_Map.insert(std::make_pair(newkey, old_it->second)); 215 m_Map.insert(std::make_pair(MaybeIntern(newkey), old_it->second));
215 } 216 }
216 m_Map.erase(old_it); 217 m_Map.erase(old_it);
217 } 218 }
218 219
219 void CPDF_Dictionary::SetIntegerFor(const CFX_ByteString& key, int i) { 220 void CPDF_Dictionary::SetIntegerFor(const CFX_ByteString& key, int i) {
220 SetFor(key, new CPDF_Number(i)); 221 SetFor(key, new CPDF_Number(i));
221 } 222 }
222 223
223 void CPDF_Dictionary::SetNameFor(const CFX_ByteString& key, 224 void CPDF_Dictionary::SetNameFor(const CFX_ByteString& key,
224 const CFX_ByteString& name) { 225 const CFX_ByteString& name) {
225 SetFor(key, new CPDF_Name(name)); 226 SetFor(key, new CPDF_Name(MaybeIntern(name)));
226 } 227 }
227 228
228 void CPDF_Dictionary::SetStringFor(const CFX_ByteString& key, 229 void CPDF_Dictionary::SetStringFor(const CFX_ByteString& key,
229 const CFX_ByteString& str) { 230 const CFX_ByteString& str) {
230 SetFor(key, new CPDF_String(str, FALSE)); 231 SetFor(key, new CPDF_String(MaybeIntern(str), FALSE));
231 } 232 }
232 233
233 void CPDF_Dictionary::SetReferenceFor(const CFX_ByteString& key, 234 void CPDF_Dictionary::SetReferenceFor(const CFX_ByteString& key,
234 CPDF_IndirectObjectHolder* pDoc, 235 CPDF_IndirectObjectHolder* pDoc,
235 uint32_t objnum) { 236 uint32_t objnum) {
236 SetFor(key, new CPDF_Reference(pDoc, objnum)); 237 SetFor(key, new CPDF_Reference(pDoc, objnum));
237 } 238 }
238 239
239 void CPDF_Dictionary::SetNumberFor(const CFX_ByteString& key, FX_FLOAT f) { 240 void CPDF_Dictionary::SetNumberFor(const CFX_ByteString& key, FX_FLOAT f) {
240 SetFor(key, new CPDF_Number(f)); 241 SetFor(key, new CPDF_Number(f));
(...skipping 17 matching lines...) Expand all
258 const CFX_Matrix& matrix) { 259 const CFX_Matrix& matrix) {
259 CPDF_Array* pArray = new CPDF_Array; 260 CPDF_Array* pArray = new CPDF_Array;
260 pArray->AddNumber(matrix.a); 261 pArray->AddNumber(matrix.a);
261 pArray->AddNumber(matrix.b); 262 pArray->AddNumber(matrix.b);
262 pArray->AddNumber(matrix.c); 263 pArray->AddNumber(matrix.c);
263 pArray->AddNumber(matrix.d); 264 pArray->AddNumber(matrix.d);
264 pArray->AddNumber(matrix.e); 265 pArray->AddNumber(matrix.e);
265 pArray->AddNumber(matrix.f); 266 pArray->AddNumber(matrix.f);
266 SetFor(key, pArray); 267 SetFor(key, pArray);
267 } 268 }
269
270 CFX_ByteString CPDF_Dictionary::MaybeIntern(const CFX_ByteString& str) {
271 return m_pPool ? m_pPool->Intern(str) : str;
272 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cfdf_document.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698