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

Side by Side Diff: core/fpdfapi/parser/cpdf_array.cpp

Issue 2384883003: Remove CPDF_Object::Release() in favor of direct delete (Closed)
Patch Set: rebase Created 4 years, 1 month 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/parser/cpdf_array.h ('k') | core/fpdfapi/parser/cpdf_array_unittest.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/parser/cpdf_array.h" 7 #include "core/fpdfapi/parser/cpdf_array.h"
8 8
9 #include <set> 9 #include <set>
10 10
11 #include "core/fpdfapi/parser/cpdf_name.h" 11 #include "core/fpdfapi/parser/cpdf_name.h"
12 #include "core/fpdfapi/parser/cpdf_number.h" 12 #include "core/fpdfapi/parser/cpdf_number.h"
13 #include "core/fpdfapi/parser/cpdf_reference.h" 13 #include "core/fpdfapi/parser/cpdf_reference.h"
14 #include "core/fpdfapi/parser/cpdf_stream.h" 14 #include "core/fpdfapi/parser/cpdf_stream.h"
15 #include "core/fpdfapi/parser/cpdf_string.h" 15 #include "core/fpdfapi/parser/cpdf_string.h"
16 #include "third_party/base/logging.h" 16 #include "third_party/base/logging.h"
17 #include "third_party/base/stl_util.h" 17 #include "third_party/base/stl_util.h"
18 18
19 CPDF_Array::CPDF_Array() {} 19 CPDF_Array::CPDF_Array() {}
20 20
21 CPDF_Array::~CPDF_Array() { 21 CPDF_Array::~CPDF_Array() {
22 // Mark the object as deleted so that it will not be deleted again 22 // Mark the object as deleted so that it will not be deleted again
23 // in case of cyclic references. 23 // in case of cyclic references.
24 m_ObjNum = kInvalidObjNum; 24 m_ObjNum = kInvalidObjNum;
25 for (auto& it : m_Objects) { 25 for (auto& it : m_Objects) {
26 if (it && it->GetObjNum() != kInvalidObjNum) 26 if (it && it->GetObjNum() != kInvalidObjNum)
27 it->Release(); 27 delete it;
28 } 28 }
29 } 29 }
30 30
31 CPDF_Object::Type CPDF_Array::GetType() const { 31 CPDF_Object::Type CPDF_Array::GetType() const {
32 return ARRAY; 32 return ARRAY;
33 } 33 }
34 34
35 bool CPDF_Array::IsArray() const { 35 bool CPDF_Array::IsArray() const {
36 return true; 36 return true;
37 } 37 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 return ToArray(GetDirectObjectAt(i)); 132 return ToArray(GetDirectObjectAt(i));
133 } 133 }
134 134
135 void CPDF_Array::RemoveAt(size_t i, size_t nCount) { 135 void CPDF_Array::RemoveAt(size_t i, size_t nCount) {
136 if (i >= m_Objects.size()) 136 if (i >= m_Objects.size())
137 return; 137 return;
138 138
139 if (nCount <= 0 || nCount > m_Objects.size() - i) 139 if (nCount <= 0 || nCount > m_Objects.size() - i)
140 return; 140 return;
141 141
142 for (size_t j = 0; j < nCount; ++j) { 142 for (size_t j = 0; j < nCount; ++j)
143 if (CPDF_Object* p = m_Objects[i + j]) 143 delete m_Objects[i + j];
144 p->Release(); 144
145 }
146 m_Objects.erase(m_Objects.begin() + i, m_Objects.begin() + i + nCount); 145 m_Objects.erase(m_Objects.begin() + i, m_Objects.begin() + i + nCount);
147 } 146 }
148 147
149 void CPDF_Array::ConvertToIndirectObjectAt(size_t i, 148 void CPDF_Array::ConvertToIndirectObjectAt(size_t i,
150 CPDF_IndirectObjectHolder* pHolder) { 149 CPDF_IndirectObjectHolder* pHolder) {
151 if (i >= m_Objects.size()) 150 if (i >= m_Objects.size())
152 return; 151 return;
153 152
154 CPDF_Object* pObj = m_Objects[i]; 153 CPDF_Object* pObj = m_Objects[i];
155 if (!pObj || pObj->IsReference()) 154 if (!pObj || pObj->IsReference())
156 return; 155 return;
157 156
158 uint32_t dwObjNum = pHolder->AddIndirectObject(pObj); 157 uint32_t dwObjNum = pHolder->AddIndirectObject(pObj);
159 m_Objects[i] = new CPDF_Reference(pHolder, dwObjNum); 158 m_Objects[i] = new CPDF_Reference(pHolder, dwObjNum);
160 } 159 }
161 160
162 void CPDF_Array::SetAt(size_t i, CPDF_Object* pObj) { 161 void CPDF_Array::SetAt(size_t i, CPDF_Object* pObj) {
163 ASSERT(IsArray()); 162 ASSERT(IsArray());
164 CHECK(!pObj || pObj->IsInline()); 163 CHECK(!pObj || pObj->IsInline());
165 if (i >= m_Objects.size()) { 164 if (i >= m_Objects.size()) {
166 ASSERT(false); 165 ASSERT(false);
167 return; 166 return;
168 } 167 }
169 if (CPDF_Object* pOld = m_Objects[i]) 168 delete m_Objects[i];
170 pOld->Release();
171
172 m_Objects[i] = pObj; 169 m_Objects[i] = pObj;
173 } 170 }
174 171
175 void CPDF_Array::InsertAt(size_t index, CPDF_Object* pObj) { 172 void CPDF_Array::InsertAt(size_t index, CPDF_Object* pObj) {
176 ASSERT(IsArray()); 173 ASSERT(IsArray());
177 CHECK(!pObj || pObj->IsInline()); 174 CHECK(!pObj || pObj->IsInline());
178 if (index >= m_Objects.size()) { 175 if (index >= m_Objects.size()) {
179 // Allocate space first. 176 // Allocate space first.
180 m_Objects.resize(index + 1, nullptr); 177 m_Objects.resize(index + 1, nullptr);
181 m_Objects[index] = pObj; 178 m_Objects[index] = pObj;
(...skipping 22 matching lines...) Expand all
204 } 201 }
205 202
206 void CPDF_Array::AddNumber(FX_FLOAT f) { 203 void CPDF_Array::AddNumber(FX_FLOAT f) {
207 Add(new CPDF_Number(f)); 204 Add(new CPDF_Number(f));
208 } 205 }
209 206
210 void CPDF_Array::AddReference(CPDF_IndirectObjectHolder* pDoc, 207 void CPDF_Array::AddReference(CPDF_IndirectObjectHolder* pDoc,
211 uint32_t objnum) { 208 uint32_t objnum) {
212 Add(new CPDF_Reference(pDoc, objnum)); 209 Add(new CPDF_Reference(pDoc, objnum));
213 } 210 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_array.h ('k') | core/fpdfapi/parser/cpdf_array_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698