OLD | NEW |
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/parser/cpdf_indirect_object_holder.h" | 7 #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h" |
8 | 8 |
9 #include "core/fpdfapi/parser/cpdf_object.h" | 9 #include "core/fpdfapi/parser/cpdf_object.h" |
10 #include "core/fpdfapi/parser/cpdf_parser.h" | 10 #include "core/fpdfapi/parser/cpdf_parser.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 CPDF_Object* CPDF_IndirectObjectHolder::GetOrParseIndirectObject( | 22 CPDF_Object* CPDF_IndirectObjectHolder::GetOrParseIndirectObject( |
23 uint32_t objnum) { | 23 uint32_t objnum) { |
24 if (objnum == 0) | 24 if (objnum == 0) |
25 return nullptr; | 25 return nullptr; |
26 | 26 |
27 CPDF_Object* pObj = GetIndirectObject(objnum); | 27 CPDF_Object* pObj = GetIndirectObject(objnum); |
28 if (pObj) | 28 if (pObj) |
29 return pObj->GetObjNum() != CPDF_Object::kInvalidObjNum ? pObj : nullptr; | 29 return pObj->GetObjNum() != CPDF_Object::kInvalidObjNum ? pObj : nullptr; |
30 | 30 |
31 pObj = ParseIndirectObject(objnum); | 31 std::unique_ptr<CPDF_Object> pNewObj = ParseIndirectObject(objnum); |
32 if (!pObj) | 32 if (!pNewObj) |
33 return nullptr; | 33 return nullptr; |
34 | 34 |
35 pObj->m_ObjNum = objnum; | 35 pNewObj->m_ObjNum = objnum; |
36 m_LastObjNum = std::max(m_LastObjNum, objnum); | 36 m_LastObjNum = std::max(m_LastObjNum, objnum); |
37 m_IndirectObjs[objnum].reset(pObj); | 37 m_IndirectObjs[objnum] = std::move(pNewObj); |
38 return pObj; | 38 return m_IndirectObjs[objnum].get(); |
39 } | 39 } |
40 | 40 |
41 CPDF_Object* CPDF_IndirectObjectHolder::ParseIndirectObject(uint32_t objnum) { | 41 std::unique_ptr<CPDF_Object> CPDF_IndirectObjectHolder::ParseIndirectObject( |
| 42 uint32_t objnum) { |
42 return nullptr; | 43 return nullptr; |
43 } | 44 } |
44 | 45 |
45 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { | 46 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { |
46 CHECK(!pObj->m_ObjNum); | 47 CHECK(!pObj->m_ObjNum); |
47 m_LastObjNum++; | 48 m_LastObjNum++; |
48 m_IndirectObjs[m_LastObjNum].release(); // TODO(tsepez): stop this leak. | 49 m_IndirectObjs[m_LastObjNum].release(); // TODO(tsepez): stop this leak. |
49 m_IndirectObjs[m_LastObjNum].reset(pObj); | 50 m_IndirectObjs[m_LastObjNum].reset(pObj); |
50 pObj->m_ObjNum = m_LastObjNum; | 51 pObj->m_ObjNum = m_LastObjNum; |
51 return m_LastObjNum; | 52 return m_LastObjNum; |
(...skipping 16 matching lines...) Expand all Loading... |
68 return true; | 69 return true; |
69 } | 70 } |
70 | 71 |
71 void CPDF_IndirectObjectHolder::DeleteIndirectObject(uint32_t objnum) { | 72 void CPDF_IndirectObjectHolder::DeleteIndirectObject(uint32_t objnum) { |
72 CPDF_Object* pObj = GetIndirectObject(objnum); | 73 CPDF_Object* pObj = GetIndirectObject(objnum); |
73 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) | 74 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) |
74 return; | 75 return; |
75 | 76 |
76 m_IndirectObjs.erase(objnum); | 77 m_IndirectObjs.erase(objnum); |
77 } | 78 } |
OLD | NEW |