Index: core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp |
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp |
index fc473319fcea05ccb171a86c4fe99524a648c991..c352c5b6e633cc954a6452b1ce186f6ee5e1d79d 100644 |
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp |
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp |
@@ -738,27 +738,38 @@ FX_BOOL CPDF_Dictionary::KeyExist(const CFX_ByteStringC& key) const { |
void* value; |
return m_Map.Lookup(key, value); |
} |
-void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, |
- CPDF_Object* pObj, |
- CPDF_IndirectObjects* pObjs) { |
- ASSERT(m_Type == PDFOBJ_DICTIONARY); |
- CPDF_Object* p = NULL; |
- m_Map.Lookup(key, (void*&)p); |
- if (p == pObj) { |
+ |
+void CPDF_Dictionary::SetAt(const CFX_ByteStringC& key, CPDF_Object* pObj) { |
+ SetAtWithIndirect(key, pObj, nullptr); |
+} |
+ |
+void CPDF_Dictionary::SetAtWithIndirect(const CFX_ByteStringC& key, |
+ CPDF_Object* pObj, |
+ CPDF_IndirectObjects* pObjs) { |
+ ASSERT(IsDictionary()); |
+ CPDF_Object* pExisting = nullptr; |
+ m_Map.Lookup(key, (void*&)pExisting); |
Tom Sepez
2015/10/24 16:50:01
nit: you know this cast is my favorite pet peeve .
Lei Zhang
2015/10/26 21:58:22
Done.
|
+ if (pExisting == pObj) |
+ return; |
+ |
+ if (pExisting) |
+ pExisting->Release(); |
+ |
+ if (!pObj) { |
+ m_Map.RemoveKey(key); |
return; |
} |
- if (p) |
- p->Release(); |
- if (pObj) { |
- if (pObj->GetObjNum()) { |
- ASSERT(pObjs != NULL); |
- pObj = new CPDF_Reference(pObjs, pObj->GetObjNum()); |
- } |
- m_Map.SetAt(key, pObj); |
+ |
+ FX_DWORD dwObjNum = pObj->GetObjNum(); |
+ if (dwObjNum) { |
+ ASSERT(pObjs); |
+ m_Map.SetAt(key, new CPDF_Reference(pObjs, dwObjNum)); |
+ pObj->Release(); |
} else { |
- m_Map.RemoveKey(key); |
+ m_Map.SetAt(key, pObj); |
} |
} |
+ |
void CPDF_Dictionary::AddValue(const CFX_ByteStringC& key, CPDF_Object* pObj) { |
ASSERT(m_Type == PDFOBJ_DICTIONARY); |
m_Map.AddValue(key, pObj); |