From f0d9d28a034fe3650c3c2d662090c1e8687ddb16 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 30 May 2018 16:40:00 +0000 Subject: Make CPDF_Document cache CPDF_Pages We cache pages not by page number, which can bounce around as pages are inserted or removed, but by page dictionary's object number. Since the page may be created under one function and used under another, we can't take the shortcut of not instantiating a render cache nor not parsing the page. Change-Id: I9a325cda8b3141153544ac53e78a51a44e6b411a Reviewed-on: https://pdfium-review.googlesource.com/32830 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- core/fpdfapi/parser/cpdf_document.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'core/fpdfapi/parser/cpdf_document.cpp') diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 7968d1b019..2e4baabe91 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -602,6 +602,19 @@ bool CPDF_Document::InsertNewPage(int iPage, CPDF_Dictionary* pPageDict) { return true; } +RetainPtr CPDF_Document::GetOrCreatePDFPage( + CPDF_Dictionary* pPageDict) { + std::pair key = {pPageDict->GetObjNum(), + pPageDict->GetGenNum()}; + if (m_PageMap[key]) + return RetainPtr(m_PageMap[key].Get()); + + auto pPage = pdfium::MakeRetain(this, pPageDict, true); + pPage->ParseContent(); + m_PageMap[key].Reset(pPage.Get()); + return pPage; +} + void CPDF_Document::DeletePage(int iPage) { CPDF_Dictionary* pPages = GetPagesDict(); if (!pPages) -- cgit v1.2.3