summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_document.h
diff options
context:
space:
mode:
authornpm <npm@chromium.org>2016-10-18 10:38:20 -0700
committerCommit bot <commit-bot@chromium.org>2016-10-18 10:38:20 -0700
commit7c29e27dae139a205755c1a29b7f3ac8b36ec0da (patch)
tree9cc6b44a5c498e7b4c0ddf3dddb4a30654852ea5 /core/fpdfapi/parser/cpdf_document.h
parentf3c5fc09f0818ec378890ade42bef40eebd3f0a9 (diff)
downloadpdfium-7c29e27dae139a205755c1a29b7f3ac8b36ec0da.tar.xz
Traverse PDF page tree only once in CPDF_Documentchromium/2895
In our current implementation of CPDF_Document::GetPage, we traverse the PDF page tree until we find the index we are looking for. This is slow when we do calls GetPage(0), GetPage(1), ... since in this case the page tree will be traversed n times if there are n pages. This CL makes sure the page tree is only traversed once. Time to load the PDF from the bug below in chrome official build: Before this CL: 1 minute 40 seconds After this CL: 5 seconds BUG=chromium:638513 Review-Url: https://codereview.chromium.org/2414423002
Diffstat (limited to 'core/fpdfapi/parser/cpdf_document.h')
-rw-r--r--core/fpdfapi/parser/cpdf_document.h17
1 files changed, 12 insertions, 5 deletions
diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h
index c557a56013..e845ea8eef 100644
--- a/core/fpdfapi/parser/cpdf_document.h
+++ b/core/fpdfapi/parser/cpdf_document.h
@@ -9,6 +9,7 @@
#include <functional>
#include <memory>
+#include <stack>
#include "core/fpdfapi/parser/cpdf_indirect_object_holder.h"
#include "core/fpdfapi/parser/cpdf_object.h"
@@ -107,10 +108,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
// Retrieve page count information by getting count value from the tree nodes
int RetrievePageCount() const;
- CPDF_Dictionary* FindPDFPage(CPDF_Dictionary* pPages,
- int iPage,
- int nPagesToGo,
- int level);
+ CPDF_Dictionary* TraversePDFPages(int iPage, int nPagesToGo);
int FindPageIndex(CPDF_Dictionary* pNode,
uint32_t& skip_count,
uint32_t objnum,
@@ -126,10 +124,19 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
FX_BOOL bVert,
CFX_ByteString basefont,
std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert);
-
+ int InsertDeletePDFPage(CPDF_Dictionary* pPages,
+ int nPagesToGo,
+ CPDF_Dictionary* pPage,
+ FX_BOOL bInsert,
+ std::set<CPDF_Dictionary*>* pVisited);
+ int InsertNewPage(int iPage,
+ CPDF_Dictionary* pPageDict,
+ CFX_ArrayTemplate<uint32_t>& pageList);
std::unique_ptr<CPDF_Parser> m_pParser;
CPDF_Dictionary* m_pRootDict;
CPDF_Dictionary* m_pInfoDict;
+ std::stack<std::pair<CPDF_Dictionary*, int>> m_pTreeTraversal;
+ int m_iLastPageTraversed;
bool m_bLinearized;
int m_iFirstPageNo;
uint32_t m_dwFirstPageObjNum;