 Chromium Code Reviews
 Chromium Code Reviews Issue 2466023002:
  Unify some code  (Closed)
    
  
    Issue 2466023002:
  Unify some code  (Closed) 
  | Index: core/fpdfapi/parser/cpdf_parser.cpp | 
| diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp | 
| index cff0f77b3247107d4a33d724480115955f432e67..eef5bc38444ceea36af6b9bd3bd6de012f6759d9 100644 | 
| --- a/core/fpdfapi/parser/cpdf_parser.cpp | 
| +++ b/core/fpdfapi/parser/cpdf_parser.cpp | 
| @@ -12,6 +12,7 @@ | 
| #include "core/fpdfapi/parser/cpdf_crypto_handler.h" | 
| #include "core/fpdfapi/parser/cpdf_dictionary.h" | 
| #include "core/fpdfapi/parser/cpdf_document.h" | 
| +#include "core/fpdfapi/parser/cpdf_linearized.h" | 
| #include "core/fpdfapi/parser/cpdf_number.h" | 
| #include "core/fpdfapi/parser/cpdf_reference.h" | 
| #include "core/fpdfapi/parser/cpdf_security_handler.h" | 
| @@ -54,8 +55,6 @@ CPDF_Parser::CPDF_Parser() | 
| m_pTrailer(nullptr), | 
| m_pEncryptDict(nullptr), | 
| m_bVersionUpdated(false), | 
| - m_pLinearized(nullptr), | 
| - m_dwFirstPageNo(0), | 
| m_dwXrefStartObjNum(0) { | 
| m_pSyntax.reset(new CPDF_SyntaxParser); | 
| } | 
| @@ -76,9 +75,6 @@ CPDF_Parser::~CPDF_Parser() { | 
| if (trailer) | 
| trailer->Release(); | 
| } | 
| - | 
| - if (m_pLinearized) | 
| - m_pLinearized->Release(); | 
| } | 
| uint32_t CPDF_Parser::GetLastObjNum() const { | 
| @@ -1414,6 +1410,10 @@ CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( | 
| return pObj; | 
| } | 
| +uint32_t CPDF_Parser::GetFirstPageNo() const { | 
| + return m_pLinearized ? m_pLinearized->GetFirstPageNo() : 0; | 
| +} | 
| + | 
| CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { | 
| if (m_pSyntax->GetKeyword() != "trailer") | 
| return nullptr; | 
| @@ -1460,35 +1460,12 @@ bool CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, | 
| return false; | 
| } | 
| - m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); | 
| + m_pLinearized = CPDF_Linearized::CreateForObject( | 
| + UniqueObject(m_pSyntax->GetObject(nullptr, objnum, gennum, true))); | 
| if (!m_pLinearized) | 
| return false; | 
| - | 
| - CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 
| - if (pDict && pDict->GetObjectFor("Linearized")) { | 
| - m_pSyntax->GetNextWord(nullptr); | 
| - | 
| - CPDF_Object* pLen = pDict->GetObjectFor("L"); | 
| - if (!pLen) { | 
| - m_pLinearized->Release(); | 
| - m_pLinearized = nullptr; | 
| - return false; | 
| - } | 
| - | 
| - if (pLen->GetInteger() != (int)pFileAccess->GetSize()) | 
| - return false; | 
| - | 
| - if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) | 
| - m_dwFirstPageNo = pNo->GetInteger(); | 
| - | 
| - if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T"))) | 
| - m_LastXRefOffset = pTable->GetInteger(); | 
| - | 
| - return true; | 
| - } | 
| - m_pLinearized->Release(); | 
| - m_pLinearized = nullptr; | 
| - return false; | 
| + m_LastXRefOffset = m_pLinearized->GetLastXRefOffset(); | 
| + return true; | 
| } | 
| CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( | 
| @@ -1511,6 +1488,7 @@ CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( | 
| m_bHasParsed = true; | 
| m_pDocument = pDocument; | 
| + m_pSyntax->GetNextWord(nullptr); | 
| 
Lei Zhang
2016/11/04 01:10:15
This is the same call that used to be in CPDF_Pars
 
snake
2016/11/04 22:39:14
Moved back for now. Will think how will be better.
 
Lei Zhang
2016/11/04 23:02:15
There's still a subtle difference. In the old code
 | 
| FX_FILESIZE dwFirstXRefOffset = m_pSyntax->SavePos(); | 
| bool bXRefRebuilt = false; | 
| @@ -1537,7 +1515,7 @@ CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( | 
| if (eRet != SUCCESS) | 
| return eRet; | 
| - m_pDocument->LoadLinearizedDoc(m_pLinearized->GetDict()); | 
| + m_pDocument->LoadLinearizedDoc(m_pLinearized.get()); | 
| if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { | 
| if (bXRefRebuilt) | 
| return FORMAT_ERROR; | 
| @@ -1550,7 +1528,7 @@ CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( | 
| if (eRet != SUCCESS) | 
| return eRet; | 
| - m_pDocument->LoadLinearizedDoc(m_pLinearized->GetDict()); | 
| + m_pDocument->LoadLinearizedDoc(m_pLinearized.get()); | 
| if (!m_pDocument->GetRoot()) | 
| return FORMAT_ERROR; | 
| } |