summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-05-30 16:40:00 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-30 16:40:00 +0000
commitf0d9d28a034fe3650c3c2d662090c1e8687ddb16 (patch)
tree6f25857014a0c76445cab264db99f355a4446e3d /core/fpdfapi/parser
parent163b4a4117bcc0b2bd1866d32205fbfb9cc01e02 (diff)
downloadpdfium-f0d9d28a034fe3650c3c2d662090c1e8687ddb16.tar.xz
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 <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/cpdf_document.cpp13
-rw-r--r--core/fpdfapi/parser/cpdf_document.h10
2 files changed, 22 insertions, 1 deletions
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_Page> CPDF_Document::GetOrCreatePDFPage(
+ CPDF_Dictionary* pPageDict) {
+ std::pair<uint32_t, uint32_t> key = {pPageDict->GetObjNum(),
+ pPageDict->GetGenNum()};
+ if (m_PageMap[key])
+ return RetainPtr<CPDF_Page>(m_PageMap[key].Get());
+
+ auto pPage = pdfium::MakeRetain<CPDF_Page>(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)
diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h
index c2774b163a..c240e77567 100644
--- a/core/fpdfapi/parser/cpdf_document.h
+++ b/core/fpdfapi/parser/cpdf_document.h
@@ -8,6 +8,7 @@
#define CORE_FPDFAPI_PARSER_CPDF_DOCUMENT_H_
#include <functional>
+#include <map>
#include <memory>
#include <set>
#include <utility>
@@ -64,6 +65,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
const CPDF_Dictionary* GetInfo() const { return m_pInfoDict.Get(); }
CPDF_Dictionary* GetInfo() { return m_pInfoDict.Get(); }
+ RetainPtr<CPDF_Page> GetOrCreatePDFPage(CPDF_Dictionary* pPageDict);
void DeletePage(int iPage);
int GetPageCount() const;
bool IsPageLoaded(int iPage) const;
@@ -167,7 +169,13 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
std::unique_ptr<CPDF_DocRenderData> m_pDocRender;
std::unique_ptr<JBig2_DocumentContext> m_pCodecContext;
std::unique_ptr<CPDF_LinkList> m_pLinksContext;
- std::vector<uint32_t> m_PageList; // Page number to page's dict objnum.
+
+ // Page number (index) to page's dict objnum.
+ std::vector<uint32_t> m_PageList;
+
+ // Dict {objnum, gennum} to page mapping.
+ std::map<std::pair<uint32_t, uint32_t>, CPDF_Page::ObservedPtr> m_PageMap;
+
UnownedPtr<Extension> m_pExtension;
};