summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-11-19 23:26:24 -0800
committerLei Zhang <thestig@chromium.org>2015-11-19 23:26:24 -0800
commitaa28c814795edfdeb0654f16e77a54f65b7d42c2 (patch)
treebe94256c75a192375e5e41bbfc41dcf074a37e72 /core/src/fpdfapi/fpdf_parser
parent5fd907b8266766152377a9836abfcac0161832fc (diff)
downloadpdfium-aa28c814795edfdeb0654f16e77a54f65b7d42c2.tar.xz
Merge to XFA: Cache object numbers in CPDF_Parser::ParseIndirectObject().
TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1458633004 . (cherry picked from commit 0c8e6c1f39f20985a3efb17292e46c476194183a) Review URL: https://codereview.chromium.org/1461693005 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 9318403766..b55ce64a23 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -141,6 +141,8 @@ void CPDF_Parser::CloseParser(FX_BOOL bReParse) {
delete pStream;
}
m_ObjectStreamMap.RemoveAll();
+ m_ObjCache.clear();
+
m_SortedOffset.RemoveAll();
m_CrossRef.RemoveAll();
m_V5Type.RemoveAll();
@@ -1200,16 +1202,23 @@ CPDF_Object* CPDF_Parser::ParseIndirectObject(CPDF_IndirectObjects* pObjList,
(uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE));
CPDF_SyntaxParser syntax;
syntax.InitParser(file.get(), 0);
- int32_t offset = GetStreamFirst(pObjStream);
- for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) {
- FX_DWORD thisnum = syntax.GetDirectNum();
- FX_DWORD thisoff = syntax.GetDirectNum();
- if (thisnum == objnum) {
- syntax.RestorePos(offset + thisoff);
- return syntax.GetObject(pObjList, 0, 0, pContext);
+ const int32_t offset = GetStreamFirst(pObjStream);
+
+ // Read object numbers from |pObjStream| into a cache.
+ if (m_ObjCache.find(pObjStream) == m_ObjCache.end()) {
+ for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) {
+ FX_DWORD thisnum = syntax.GetDirectNum();
+ FX_DWORD thisoff = syntax.GetDirectNum();
+ m_ObjCache[pObjStream][thisnum] = thisoff;
}
}
- return nullptr;
+
+ const auto it = m_ObjCache[pObjStream].find(objnum);
+ if (it == m_ObjCache[pObjStream].end())
+ return nullptr;
+
+ syntax.RestorePos(offset + it->second);
+ return syntax.GetObject(pObjList, 0, 0, pContext);
}
CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) {
@@ -1659,6 +1668,8 @@ FX_DWORD CPDF_Parser::LoadLinearizedMainXRefTable() {
delete pStream;
}
m_ObjectStreamMap.RemoveAll();
+ m_ObjCache.clear();
+
if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) &&
!LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) {
m_LastXRefOffset = 0;