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

Side by Side Diff: core/fpdfapi/page/cpdf_streamcontentparser.cpp

Issue 2520133002: Remove some WrapUnique() calls by returing unique_ptrs (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/page/cpdf_streamcontentparser.h ('k') | core/fpdfapi/page/cpdf_streamparser.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/page/cpdf_streamcontentparser.h" 7 #include "core/fpdfapi/page/cpdf_streamcontentparser.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 delete m_pLastImageDict; 299 delete m_pLastImageDict;
300 delete m_pLastCloneImageDict; 300 delete m_pLastCloneImageDict;
301 } 301 }
302 302
303 int CPDF_StreamContentParser::GetNextParamPos() { 303 int CPDF_StreamContentParser::GetNextParamPos() {
304 if (m_ParamCount == kParamBufSize) { 304 if (m_ParamCount == kParamBufSize) {
305 m_ParamStartPos++; 305 m_ParamStartPos++;
306 if (m_ParamStartPos == kParamBufSize) { 306 if (m_ParamStartPos == kParamBufSize) {
307 m_ParamStartPos = 0; 307 m_ParamStartPos = 0;
308 } 308 }
309 if (m_ParamBuf[m_ParamStartPos].m_Type == 0) 309 if (m_ParamBuf[m_ParamStartPos].m_Type == ContentParam::OBJECT)
310 delete m_ParamBuf[m_ParamStartPos].m_pObject; 310 m_ParamBuf[m_ParamStartPos].m_pObject.reset();
311 311
312 return m_ParamStartPos; 312 return m_ParamStartPos;
313 } 313 }
314 int index = m_ParamStartPos + m_ParamCount; 314 int index = m_ParamStartPos + m_ParamCount;
315 if (index >= kParamBufSize) { 315 if (index >= kParamBufSize) {
316 index -= kParamBufSize; 316 index -= kParamBufSize;
317 } 317 }
318 m_ParamCount++; 318 m_ParamCount++;
319 return index; 319 return index;
320 } 320 }
321 321
322 void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) { 322 void CPDF_StreamContentParser::AddNameParam(const FX_CHAR* name, int len) {
323 CFX_ByteStringC bsName(name, len); 323 CFX_ByteStringC bsName(name, len);
324 ContentParam& param = m_ParamBuf[GetNextParamPos()]; 324 ContentParam& param = m_ParamBuf[GetNextParamPos()];
325 if (len > 32) { 325 if (len > 32) {
326 param.m_Type = ContentParam::OBJECT; 326 param.m_Type = ContentParam::OBJECT;
327 param.m_pObject = 327 param.m_pObject = pdfium::MakeUnique<CPDF_Name>(
328 new CPDF_Name(m_pDocument->GetByteStringPool(), PDF_NameDecode(bsName)); 328 m_pDocument->GetByteStringPool(), PDF_NameDecode(bsName));
329 } else { 329 } else {
330 param.m_Type = ContentParam::NAME; 330 param.m_Type = ContentParam::NAME;
331 if (bsName.Find('#') == -1) { 331 if (bsName.Find('#') == -1) {
332 FXSYS_memcpy(param.m_Name.m_Buffer, name, len); 332 FXSYS_memcpy(param.m_Name.m_Buffer, name, len);
333 param.m_Name.m_Len = len; 333 param.m_Name.m_Len = len;
334 } else { 334 } else {
335 CFX_ByteString str = PDF_NameDecode(bsName); 335 CFX_ByteString str = PDF_NameDecode(bsName);
336 FXSYS_memcpy(param.m_Name.m_Buffer, str.c_str(), str.GetLength()); 336 FXSYS_memcpy(param.m_Name.m_Buffer, str.c_str(), str.GetLength());
337 param.m_Name.m_Len = str.GetLength(); 337 param.m_Name.m_Len = str.GetLength();
338 } 338 }
339 } 339 }
340 } 340 }
341 341
342 void CPDF_StreamContentParser::AddNumberParam(const FX_CHAR* str, int len) { 342 void CPDF_StreamContentParser::AddNumberParam(const FX_CHAR* str, int len) {
343 ContentParam& param = m_ParamBuf[GetNextParamPos()]; 343 ContentParam& param = m_ParamBuf[GetNextParamPos()];
344 param.m_Type = ContentParam::NUMBER; 344 param.m_Type = ContentParam::NUMBER;
345 param.m_Number.m_bInteger = 345 param.m_Number.m_bInteger =
346 FX_atonum(CFX_ByteStringC(str, len), &param.m_Number.m_Integer); 346 FX_atonum(CFX_ByteStringC(str, len), &param.m_Number.m_Integer);
347 } 347 }
348 348
349 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) { 349 void CPDF_StreamContentParser::AddObjectParam(
350 std::unique_ptr<CPDF_Object> pObj) {
350 ContentParam& param = m_ParamBuf[GetNextParamPos()]; 351 ContentParam& param = m_ParamBuf[GetNextParamPos()];
351 param.m_Type = ContentParam::OBJECT; 352 param.m_Type = ContentParam::OBJECT;
352 param.m_pObject = pObj; 353 param.m_pObject = std::move(pObj);
353 } 354 }
354 355
355 void CPDF_StreamContentParser::ClearAllParams() { 356 void CPDF_StreamContentParser::ClearAllParams() {
356 uint32_t index = m_ParamStartPos; 357 uint32_t index = m_ParamStartPos;
357 for (uint32_t i = 0; i < m_ParamCount; i++) { 358 for (uint32_t i = 0; i < m_ParamCount; i++) {
358 if (m_ParamBuf[index].m_Type == 0) 359 if (m_ParamBuf[index].m_Type == ContentParam::OBJECT)
359 delete m_ParamBuf[index].m_pObject; 360 m_ParamBuf[index].m_pObject.reset();
360
361 index++; 361 index++;
362 if (index == kParamBufSize) { 362 if (index == kParamBufSize)
363 index = 0; 363 index = 0;
364 }
365 } 364 }
366 m_ParamStartPos = 0; 365 m_ParamStartPos = 0;
367 m_ParamCount = 0; 366 m_ParamCount = 0;
368 } 367 }
369 368
370 CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) { 369 CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) {
371 if (index >= m_ParamCount) { 370 if (index >= m_ParamCount) {
372 return nullptr; 371 return nullptr;
373 } 372 }
374 int real_index = m_ParamStartPos + m_ParamCount - index - 1; 373 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
375 if (real_index >= kParamBufSize) { 374 if (real_index >= kParamBufSize) {
376 real_index -= kParamBufSize; 375 real_index -= kParamBufSize;
377 } 376 }
378 ContentParam& param = m_ParamBuf[real_index]; 377 ContentParam& param = m_ParamBuf[real_index];
379 if (param.m_Type == ContentParam::NUMBER) { 378 if (param.m_Type == ContentParam::NUMBER) {
380 CPDF_Number* pNumber = param.m_Number.m_bInteger
381 ? new CPDF_Number(param.m_Number.m_Integer)
382 : new CPDF_Number(param.m_Number.m_Float);
383
384 param.m_Type = ContentParam::OBJECT; 379 param.m_Type = ContentParam::OBJECT;
385 param.m_pObject = pNumber; 380 param.m_pObject =
386 return pNumber; 381 param.m_Number.m_bInteger
382 ? pdfium::MakeUnique<CPDF_Number>(param.m_Number.m_Integer)
383 : pdfium::MakeUnique<CPDF_Number>(param.m_Number.m_Float);
384 return param.m_pObject.get();
387 } 385 }
388 if (param.m_Type == ContentParam::NAME) { 386 if (param.m_Type == ContentParam::NAME) {
389 CPDF_Name* pName = new CPDF_Name( 387 param.m_Type = ContentParam::OBJECT;
388 param.m_pObject = pdfium::MakeUnique<CPDF_Name>(
390 m_pDocument->GetByteStringPool(), 389 m_pDocument->GetByteStringPool(),
391 CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len)); 390 CFX_ByteString(param.m_Name.m_Buffer, param.m_Name.m_Len));
392 param.m_Type = ContentParam::OBJECT; 391 return param.m_pObject.get();
393 param.m_pObject = pName;
394 return pName;
395 } 392 }
396 if (param.m_Type == ContentParam::OBJECT) { 393 if (param.m_Type == ContentParam::OBJECT)
397 return param.m_pObject; 394 return param.m_pObject.get();
398 } 395
399 ASSERT(false); 396 ASSERT(false);
400 return nullptr; 397 return nullptr;
401 } 398 }
402 399
403 CFX_ByteString CPDF_StreamContentParser::GetString(uint32_t index) { 400 CFX_ByteString CPDF_StreamContentParser::GetString(uint32_t index) {
404 if (index >= m_ParamCount) { 401 if (index >= m_ParamCount) {
405 return CFX_ByteString(); 402 return CFX_ByteString();
406 } 403 }
407 int real_index = m_ParamStartPos + m_ParamCount - index - 1; 404 int real_index = m_ParamStartPos + m_ParamCount - index - 1;
408 if (real_index >= kParamBufSize) { 405 if (real_index >= kParamBufSize) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 m_pSyntax->SetPos(savePos); 641 m_pSyntax->SetPos(savePos);
645 delete pDict; 642 delete pDict;
646 return; 643 return;
647 } 644 }
648 } 645 }
649 if (type != CPDF_StreamParser::Name) { 646 if (type != CPDF_StreamParser::Name) {
650 break; 647 break;
651 } 648 }
652 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, 649 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1,
653 m_pSyntax->GetWordSize() - 1); 650 m_pSyntax->GetWordSize() - 1);
654 auto pObj = pdfium::WrapUnique(m_pSyntax->ReadNextObject(false, 0)); 651 auto pObj = m_pSyntax->ReadNextObject(false, 0);
655 if (!key.IsEmpty()) { 652 if (!key.IsEmpty()) {
656 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; 653 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0;
657 if (dwObjNum) 654 if (dwObjNum)
658 pDict->SetNewFor<CPDF_Reference>(key, m_pDocument, dwObjNum); 655 pDict->SetNewFor<CPDF_Reference>(key, m_pDocument, dwObjNum);
659 else 656 else
660 pDict->SetFor(key, std::move(pObj)); 657 pDict->SetFor(key, std::move(pObj));
661 } 658 }
662 } 659 }
663 ReplaceAbbr(pDict); 660 ReplaceAbbr(pDict);
664 CPDF_Object* pCSObj = nullptr; 661 CPDF_Object* pCSObj = nullptr;
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 } 1658 }
1662 default: 1659 default:
1663 bProcessed = false; 1660 bProcessed = false;
1664 } 1661 }
1665 if (!bProcessed) { 1662 if (!bProcessed) {
1666 m_pSyntax->SetPos(last_pos); 1663 m_pSyntax->SetPos(last_pos);
1667 return; 1664 return;
1668 } 1665 }
1669 } 1666 }
1670 } 1667 }
1668
1669 CPDF_StreamContentParser::ContentParam::ContentParam() {}
1670
1671 CPDF_StreamContentParser::ContentParam::~ContentParam() {}
OLDNEW
« no previous file with comments | « core/fpdfapi/page/cpdf_streamcontentparser.h ('k') | core/fpdfapi/page/cpdf_streamparser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698