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

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

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

Powered by Google App Engine
This is Rietveld 408576698