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

Side by Side Diff: core/fpdfapi/fpdf_page/fpdf_page_parser.cpp

Issue 2384883003: Remove CPDF_Object::Release() in favor of direct delete (Closed)
Patch Set: Remove ScopedDict typedefs 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
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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_page/pageint.h" 7 #include "core/fpdfapi/fpdf_page/pageint.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 m_pCurStates->m_ColorState.Emplace(); 241 m_pCurStates->m_ColorState.Emplace();
242 } 242 }
243 for (size_t i = 0; i < FX_ArraySize(m_Type3Data); ++i) { 243 for (size_t i = 0; i < FX_ArraySize(m_Type3Data); ++i) {
244 m_Type3Data[i] = 0.0; 244 m_Type3Data[i] = 0.0;
245 } 245 }
246 } 246 }
247 247
248 CPDF_StreamContentParser::~CPDF_StreamContentParser() { 248 CPDF_StreamContentParser::~CPDF_StreamContentParser() {
249 ClearAllParams(); 249 ClearAllParams();
250 FX_Free(m_pPathPoints); 250 FX_Free(m_pPathPoints);
251 if (m_pLastImageDict) { 251 delete m_pLastImageDict;
252 m_pLastImageDict->Release(); 252 delete m_pLastCloneImageDict;
253 }
254 if (m_pLastCloneImageDict) {
255 m_pLastCloneImageDict->Release();
256 }
257 } 253 }
258 254
259 int CPDF_StreamContentParser::GetNextParamPos() { 255 int CPDF_StreamContentParser::GetNextParamPos() {
260 if (m_ParamCount == PARAM_BUF_SIZE) { 256 if (m_ParamCount == PARAM_BUF_SIZE) {
261 m_ParamStartPos++; 257 m_ParamStartPos++;
262 if (m_ParamStartPos == PARAM_BUF_SIZE) { 258 if (m_ParamStartPos == PARAM_BUF_SIZE)
263 m_ParamStartPos = 0; 259 m_ParamStartPos = 0;
264 } 260
265 if (m_ParamBuf[m_ParamStartPos].m_Type == 0) { 261 if (m_ParamBuf[m_ParamStartPos].m_Type == 0)
266 if (CPDF_Object* pObject = m_ParamBuf[m_ParamStartPos].m_pObject) 262 delete m_ParamBuf[m_ParamStartPos].m_pObject;
267 pObject->Release(); 263
268 }
269 return m_ParamStartPos; 264 return m_ParamStartPos;
270 } 265 }
271 int index = m_ParamStartPos + m_ParamCount; 266 int index = m_ParamStartPos + m_ParamCount;
272 if (index >= PARAM_BUF_SIZE) { 267 if (index >= PARAM_BUF_SIZE) {
273 index -= PARAM_BUF_SIZE; 268 index -= PARAM_BUF_SIZE;
274 } 269 }
275 m_ParamCount++; 270 m_ParamCount++;
276 return index; 271 return index;
277 } 272 }
278 273
(...skipping 26 matching lines...) Expand all
305 300
306 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) { 301 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) {
307 ContentParam& param = m_ParamBuf[GetNextParamPos()]; 302 ContentParam& param = m_ParamBuf[GetNextParamPos()];
308 param.m_Type = ContentParam::OBJECT; 303 param.m_Type = ContentParam::OBJECT;
309 param.m_pObject = pObj; 304 param.m_pObject = pObj;
310 } 305 }
311 306
312 void CPDF_StreamContentParser::ClearAllParams() { 307 void CPDF_StreamContentParser::ClearAllParams() {
313 uint32_t index = m_ParamStartPos; 308 uint32_t index = m_ParamStartPos;
314 for (uint32_t i = 0; i < m_ParamCount; i++) { 309 for (uint32_t i = 0; i < m_ParamCount; i++) {
315 if (m_ParamBuf[index].m_Type == 0) { 310 if (m_ParamBuf[index].m_Type == 0)
316 if (CPDF_Object* pObject = m_ParamBuf[index].m_pObject) 311 delete m_ParamBuf[index].m_pObject;
317 pObject->Release(); 312
318 }
319 index++; 313 index++;
320 if (index == PARAM_BUF_SIZE) { 314 if (index == PARAM_BUF_SIZE)
321 index = 0; 315 index = 0;
322 }
323 } 316 }
324 m_ParamStartPos = 0; 317 m_ParamStartPos = 0;
325 m_ParamCount = 0; 318 m_ParamCount = 0;
326 } 319 }
327 320
328 CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) { 321 CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) {
329 if (index >= m_ParamCount) { 322 if (index >= m_ParamCount) {
330 return nullptr; 323 return nullptr;
331 } 324 }
332 int real_index = m_ParamStartPos + m_ParamCount - index - 1; 325 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 FX_FILESIZE savePos = m_pSyntax->GetPos(); 585 FX_FILESIZE savePos = m_pSyntax->GetPos();
593 CPDF_Dictionary* pDict = 586 CPDF_Dictionary* pDict =
594 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); 587 new CPDF_Dictionary(m_pDocument->GetByteStringPool());
595 while (1) { 588 while (1) {
596 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); 589 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement();
597 if (type == CPDF_StreamParser::Keyword) { 590 if (type == CPDF_StreamParser::Keyword) {
598 CFX_ByteString bsKeyword(m_pSyntax->GetWordBuf(), 591 CFX_ByteString bsKeyword(m_pSyntax->GetWordBuf(),
599 m_pSyntax->GetWordSize()); 592 m_pSyntax->GetWordSize());
600 if (bsKeyword != "ID") { 593 if (bsKeyword != "ID") {
601 m_pSyntax->SetPos(savePos); 594 m_pSyntax->SetPos(savePos);
602 pDict->Release(); 595 delete pDict;
603 return; 596 return;
604 } 597 }
605 } 598 }
606 if (type != CPDF_StreamParser::Name) { 599 if (type != CPDF_StreamParser::Name) {
607 break; 600 break;
608 } 601 }
609 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, 602 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1,
610 m_pSyntax->GetWordSize() - 1); 603 m_pSyntax->GetWordSize() - 1);
611 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( 604 std::unique_ptr<CPDF_Object> pObj(m_pSyntax->ReadNextObject(false, 0));
612 m_pSyntax->ReadNextObject(false, 0));
613 if (!key.IsEmpty()) { 605 if (!key.IsEmpty()) {
614 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; 606 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0;
615 if (dwObjNum) 607 if (dwObjNum)
616 pDict->SetReferenceFor(key, m_pDocument, dwObjNum); 608 pDict->SetReferenceFor(key, m_pDocument, dwObjNum);
617 else 609 else
618 pDict->SetFor(key, pObj.release()); 610 pDict->SetFor(key, pObj.release());
619 } 611 }
620 } 612 }
621 PDF_ReplaceAbbr(pDict); 613 PDF_ReplaceAbbr(pDict);
622 CPDF_Object* pCSObj = nullptr; 614 CPDF_Object* pCSObj = nullptr;
(...skipping 22 matching lines...) Expand all
645 } 637 }
646 if (m_pSyntax->GetWordSize() == 2 && m_pSyntax->GetWordBuf()[0] == 'E' && 638 if (m_pSyntax->GetWordSize() == 2 && m_pSyntax->GetWordBuf()[0] == 'E' &&
647 m_pSyntax->GetWordBuf()[1] == 'I') { 639 m_pSyntax->GetWordBuf()[1] == 'I') {
648 break; 640 break;
649 } 641 }
650 } 642 }
651 pDict->SetNameFor("Subtype", "Image"); 643 pDict->SetNameFor("Subtype", "Image");
652 CPDF_ImageObject* pImgObj = AddImage(pStream, nullptr, true); 644 CPDF_ImageObject* pImgObj = AddImage(pStream, nullptr, true);
653 if (!pImgObj) { 645 if (!pImgObj) {
654 if (pStream) { 646 if (pStream) {
655 pStream->Release(); 647 delete pStream;
656 } else { 648 } else {
657 pDict->Release(); 649 delete pDict;
658 } 650 }
659 } 651 }
660 } 652 }
661 653
662 void CPDF_StreamContentParser::Handle_BeginMarkedContent() { 654 void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
663 m_CurContentMark.AddMark(GetString(0), nullptr, FALSE); 655 m_CurContentMark.AddMark(GetString(0), nullptr, FALSE);
664 } 656 }
665 657
666 void CPDF_StreamContentParser::Handle_BeginText() { 658 void CPDF_StreamContentParser::Handle_BeginText() {
667 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); 659 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0);
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 } else { 1665 } else {
1674 PDF_ReplaceAbbr(pElement); 1666 PDF_ReplaceAbbr(pElement);
1675 } 1667 }
1676 } 1668 }
1677 break; 1669 break;
1678 } 1670 }
1679 default: 1671 default:
1680 break; 1672 break;
1681 } 1673 }
1682 } 1674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698