From 3fab4e35539e29c4ded08a424db3b1c7fbfa03fc Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Wed, 23 Aug 2017 22:16:13 +0300 Subject: Optimize receiving page, if it have not obj num. Make all pages dictionary are not inlined. Original fix: https://codereview.chromium.org/2491583002 Change-Id: Ie3aa662182a70ef6ef1d6121c0576c171e0060dd Reviewed-on: https://pdfium-review.googlesource.com/11810 Reviewed-by: dsinclair Commit-Queue: Art Snake --- core/fpdfapi/parser/cpdf_document.cpp | 10 +--------- core/fpdfapi/parser/cpdf_document_unittest.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 9bfb16b97e..6aedc09d14 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -426,6 +426,7 @@ CPDF_Dictionary* CPDF_Document::TraversePDFPages(int iPage, i++) { if (*nPagesToGo == 0) break; + pKidList->ConvertToIndirectObjectAt(i, this); CPDF_Dictionary* pKid = pKidList->GetDictAt(i); if (!pKid) { (*nPagesToGo)--; @@ -499,15 +500,6 @@ CPDF_Dictionary* CPDF_Document::GetPage(int iPage) { if (!pPages) return nullptr; - if (iPage - m_iNextPageToTraverse + 1 <= 0) { - // This can happen when the page does not have an object number. On repeated - // calls to this function for the same page index, this condition causes - // TraversePDFPages() to incorrectly return nullptr. - // Example "testing/corpus/fx/other/jetman_std.pdf" - // We should restart traversing in this case. - // TODO(art-snake): optimize this. - ResetTraversal(); - } if (m_pTreeTraversal.empty()) { ResetTraversal(); m_pTreeTraversal.push_back(std::make_pair(pPages, 0)); diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp index 2715508015..9e03c96697 100644 --- a/core/fpdfapi/parser/cpdf_document_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp @@ -113,7 +113,7 @@ class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document { allPages->AddNew( this, AddIndirectObject(CreateNumberedPage(1))->GetObjNum()); // Page without pageNum. - allPages->Add(CreateNumberedPage(2)); + inlined_page_ = allPages->Add(CreateNumberedPage(2)); CPDF_Dictionary* pagesDict = CreatePageTreeNode(std::move(allPages), this, 3); m_pOwnedRootDict = pdfium::MakeUnique(); @@ -123,8 +123,11 @@ class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document { m_PageList.resize(3); } + const CPDF_Object* inlined_page() const { return inlined_page_; } + private: std::unique_ptr m_pOwnedRootDict; + const CPDF_Object* inlined_page_; }; class TestLinearized : public CPDF_LinearizedHeader { @@ -171,12 +174,11 @@ TEST_F(cpdf_document_test, GetPages) { } TEST_F(cpdf_document_test, GetPageWithoutObjNumTwice) { - std::unique_ptr document = - pdfium::MakeUnique(); + auto document = pdfium::MakeUnique(); const CPDF_Dictionary* page = document->GetPage(2); ASSERT_TRUE(page); - // This is page without obj num. - ASSERT_EQ(0ul, page->GetObjNum()); + ASSERT_EQ(document->inlined_page(), page); + const CPDF_Dictionary* second_call_page = document->GetPage(2); EXPECT_TRUE(second_call_page); EXPECT_EQ(page, second_call_page); -- cgit v1.2.3