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

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp

Issue 2345063002: Use string pools in some dictionaries (Closed)
Patch Set: windows compilation Created 4 years, 3 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 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/fpdf_parser/cpdf_syntax_parser.h" 7 #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 19 matching lines...) Expand all
30 CFX_ByteStringC m_bsTag; 30 CFX_ByteStringC m_bsTag;
31 FX_STRSIZE m_Offset; 31 FX_STRSIZE m_Offset;
32 }; 32 };
33 33
34 } // namespace 34 } // namespace
35 35
36 // static 36 // static
37 int CPDF_SyntaxParser::s_CurrentRecursionDepth = 0; 37 int CPDF_SyntaxParser::s_CurrentRecursionDepth = 0;
38 38
39 CPDF_SyntaxParser::CPDF_SyntaxParser() 39 CPDF_SyntaxParser::CPDF_SyntaxParser()
40 : m_MetadataObjnum(0), 40 : m_MetadataObjnum(0),
Lei Zhang 2016/09/20 23:48:23 Use a delegate ctor? : CPDF_SyntaxParser(nullptr)
Tom Sepez 2016/09/27 22:36:59 done
41 m_pFileAccess(nullptr), 41 m_pFileAccess(nullptr),
42 m_pFileBuf(nullptr), 42 m_pFileBuf(nullptr),
43 m_BufSize(CPDF_ModuleMgr::kFileBufSize) {} 43 m_BufSize(CPDF_ModuleMgr::kFileBufSize),
44 m_pPool(nullptr) {}
45
46 CPDF_SyntaxParser::CPDF_SyntaxParser(CFX_ByteStringPool* pPool)
47 : m_MetadataObjnum(0),
48 m_pFileAccess(nullptr),
49 m_pFileBuf(nullptr),
50 m_BufSize(CPDF_ModuleMgr::kFileBufSize),
51 m_pPool(pPool) {}
44 52
45 CPDF_SyntaxParser::~CPDF_SyntaxParser() { 53 CPDF_SyntaxParser::~CPDF_SyntaxParser() {
46 FX_Free(m_pFileBuf); 54 FX_Free(m_pFileBuf);
47 } 55 }
48 56
49 FX_BOOL CPDF_SyntaxParser::GetCharAt(FX_FILESIZE pos, uint8_t& ch) { 57 FX_BOOL CPDF_SyntaxParser::GetCharAt(FX_FILESIZE pos, uint8_t& ch) {
50 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); 58 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos);
51 m_Pos = pos; 59 m_Pos = pos;
52 return GetNextChar(ch); 60 return GetNextChar(ch);
53 } 61 }
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 if (word == "true" || word == "false") 410 if (word == "true" || word == "false")
403 return new CPDF_Boolean(word == "true"); 411 return new CPDF_Boolean(word == "true");
404 412
405 if (word == "null") 413 if (word == "null")
406 return new CPDF_Null; 414 return new CPDF_Null;
407 415
408 if (word == "(") { 416 if (word == "(") {
409 CFX_ByteString str = ReadString(); 417 CFX_ByteString str = ReadString();
410 if (m_pCryptoHandler && bDecrypt) 418 if (m_pCryptoHandler && bDecrypt)
411 m_pCryptoHandler->Decrypt(objnum, gennum, str); 419 m_pCryptoHandler->Decrypt(objnum, gennum, str);
412 return new CPDF_String(str, FALSE); 420 return new CPDF_String(MaybeIntern(str), FALSE);
413 } 421 }
414 422
415 if (word == "<") { 423 if (word == "<") {
416 CFX_ByteString str = ReadHexString(); 424 CFX_ByteString str = ReadHexString();
417 if (m_pCryptoHandler && bDecrypt) 425 if (m_pCryptoHandler && bDecrypt)
418 m_pCryptoHandler->Decrypt(objnum, gennum, str); 426 m_pCryptoHandler->Decrypt(objnum, gennum, str);
419 427 return new CPDF_String(MaybeIntern(str), TRUE);
420 return new CPDF_String(str, TRUE);
421 } 428 }
422 429
423 if (word == "[") { 430 if (word == "[") {
424 CPDF_Array* pArray = new CPDF_Array; 431 CPDF_Array* pArray = new CPDF_Array;
425 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true)) 432 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true))
426 pArray->Add(pObj); 433 pArray->Add(pObj);
427 434
428 return pArray; 435 return pArray;
429 } 436 }
430 437
431 if (word[0] == '/') { 438 if (word[0] == '/') {
432 return new CPDF_Name( 439 return new CPDF_Name(MaybeIntern(
433 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); 440 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))));
434 } 441 }
435 442
436 if (word == "<<") { 443 if (word == "<<") {
437 int32_t nKeys = 0; 444 int32_t nKeys = 0;
438 FX_FILESIZE dwSignValuePos = 0; 445 FX_FILESIZE dwSignValuePos = 0;
439 446
440 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( 447 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict(
441 new CPDF_Dictionary); 448 new CPDF_Dictionary(m_pPool));
442 while (1) { 449 while (1) {
443 CFX_ByteString key = GetNextWord(nullptr); 450 CFX_ByteString key = GetNextWord(nullptr);
444 if (key.IsEmpty()) 451 if (key.IsEmpty())
445 return nullptr; 452 return nullptr;
446 453
447 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); 454 FX_FILESIZE SavedPos = m_Pos - key.GetLength();
448 if (key == ">>") 455 if (key == ">>")
449 break; 456 break;
450 457
451 if (key == "endobj") { 458 if (key == "endobj") {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 if (word == "true" || word == "false") 531 if (word == "true" || word == "false")
525 return new CPDF_Boolean(word == "true"); 532 return new CPDF_Boolean(word == "true");
526 533
527 if (word == "null") 534 if (word == "null")
528 return new CPDF_Null; 535 return new CPDF_Null;
529 536
530 if (word == "(") { 537 if (word == "(") {
531 CFX_ByteString str = ReadString(); 538 CFX_ByteString str = ReadString();
532 if (m_pCryptoHandler) 539 if (m_pCryptoHandler)
533 m_pCryptoHandler->Decrypt(objnum, gennum, str); 540 m_pCryptoHandler->Decrypt(objnum, gennum, str);
534 return new CPDF_String(str, FALSE); 541 return new CPDF_String(MaybeIntern(str), FALSE);
535 } 542 }
536 543
537 if (word == "<") { 544 if (word == "<") {
538 CFX_ByteString str = ReadHexString(); 545 CFX_ByteString str = ReadHexString();
539 if (m_pCryptoHandler) 546 if (m_pCryptoHandler)
540 m_pCryptoHandler->Decrypt(objnum, gennum, str); 547 m_pCryptoHandler->Decrypt(objnum, gennum, str);
541 return new CPDF_String(str, TRUE); 548 return new CPDF_String(MaybeIntern(str), TRUE);
542 } 549 }
543 550
544 if (word == "[") { 551 if (word == "[") {
545 std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( 552 std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray(
546 new CPDF_Array); 553 new CPDF_Array);
547 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true)) 554 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true))
548 pArray->Add(pObj); 555 pArray->Add(pObj);
549 556
550 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr; 557 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr;
551 } 558 }
552 559
553 if (word[0] == '/') { 560 if (word[0] == '/') {
554 return new CPDF_Name( 561 return new CPDF_Name(MaybeIntern(
555 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); 562 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))));
556 } 563 }
557 564
558 if (word == "<<") { 565 if (word == "<<") {
559 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( 566 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict(
560 new CPDF_Dictionary); 567 new CPDF_Dictionary(m_pPool));
561 while (1) { 568 while (1) {
562 FX_FILESIZE SavedPos = m_Pos; 569 FX_FILESIZE SavedPos = m_Pos;
563 CFX_ByteString key = GetNextWord(nullptr); 570 CFX_ByteString key = GetNextWord(nullptr);
564 if (key.IsEmpty()) 571 if (key.IsEmpty())
565 return nullptr; 572 return nullptr;
566 573
567 if (key == ">>") 574 if (key == ">>")
568 break; 575 break;
569 576
570 if (key == "endobj") { 577 if (key == "endobj") {
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 if (limit && m_Pos == limit) 987 if (limit && m_Pos == limit)
981 return -1; 988 return -1;
982 } 989 }
983 return -1; 990 return -1;
984 } 991 }
985 992
986 void CPDF_SyntaxParser::SetEncrypt( 993 void CPDF_SyntaxParser::SetEncrypt(
987 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { 994 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) {
988 m_pCryptoHandler = std::move(pCryptoHandler); 995 m_pCryptoHandler = std::move(pCryptoHandler);
989 } 996 }
997
998 CFX_ByteString CPDF_SyntaxParser::MaybeIntern(const CFX_ByteString& str) {
999 return m_pPool ? m_pPool->Intern(str) : str;
1000 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698