Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 1458633004: Cache object numbers in CPDF_Parser::ParseIndirectObject(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/include/fpdfapi/fpdf_parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "parser_int.h" 7 #include "parser_int.h"
8 8
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 m_Syntax.m_pFileAccess = NULL; 134 m_Syntax.m_pFileAccess = NULL;
135 } 135 }
136 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); 136 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition();
137 while (pos) { 137 while (pos) {
138 void* objnum; 138 void* objnum;
139 CPDF_StreamAcc* pStream; 139 CPDF_StreamAcc* pStream;
140 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); 140 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream);
141 delete pStream; 141 delete pStream;
142 } 142 }
143 m_ObjectStreamMap.RemoveAll(); 143 m_ObjectStreamMap.RemoveAll();
144 m_ObjCache.clear();
145
144 m_SortedOffset.RemoveAll(); 146 m_SortedOffset.RemoveAll();
145 m_CrossRef.RemoveAll(); 147 m_CrossRef.RemoveAll();
146 m_V5Type.RemoveAll(); 148 m_V5Type.RemoveAll();
147 m_ObjVersion.RemoveAll(); 149 m_ObjVersion.RemoveAll();
148 int32_t iLen = m_Trailers.GetSize(); 150 int32_t iLen = m_Trailers.GetSize();
149 for (int32_t i = 0; i < iLen; ++i) { 151 for (int32_t i = 0; i < iLen; ++i) {
150 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i)) 152 if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i))
151 trailer->Release(); 153 trailer->Release();
152 } 154 }
153 m_Trailers.RemoveAll(); 155 m_Trailers.RemoveAll();
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 return nullptr; 1195 return nullptr;
1194 1196
1195 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum]); 1197 CPDF_StreamAcc* pObjStream = GetObjectStream((FX_DWORD)m_CrossRef[objnum]);
1196 if (!pObjStream) 1198 if (!pObjStream)
1197 return nullptr; 1199 return nullptr;
1198 1200
1199 ScopedFileStream file(FX_CreateMemoryStream( 1201 ScopedFileStream file(FX_CreateMemoryStream(
1200 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); 1202 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE));
1201 CPDF_SyntaxParser syntax; 1203 CPDF_SyntaxParser syntax;
1202 syntax.InitParser(file.get(), 0); 1204 syntax.InitParser(file.get(), 0);
1203 int32_t offset = GetStreamFirst(pObjStream); 1205 const int32_t offset = GetStreamFirst(pObjStream);
1204 for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) { 1206
1205 FX_DWORD thisnum = syntax.GetDirectNum(); 1207 // Read object numbers from |pObjStream| into a cache.
1206 FX_DWORD thisoff = syntax.GetDirectNum(); 1208 if (m_ObjCache.find(pObjStream) == m_ObjCache.end()) {
1207 if (thisnum == objnum) { 1209 for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) {
1208 syntax.RestorePos(offset + thisoff); 1210 FX_DWORD thisnum = syntax.GetDirectNum();
1209 return syntax.GetObject(pObjList, 0, 0, pContext); 1211 FX_DWORD thisoff = syntax.GetDirectNum();
1212 m_ObjCache[pObjStream][thisnum] = thisoff;
1210 } 1213 }
1211 } 1214 }
1212 return nullptr; 1215
1216 const auto it = m_ObjCache[pObjStream].find(objnum);
1217 if (it == m_ObjCache[pObjStream].end())
1218 return nullptr;
1219
1220 syntax.RestorePos(offset + it->second);
1221 return syntax.GetObject(pObjList, 0, 0, pContext);
1213 } 1222 }
1214 1223
1215 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { 1224 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) {
1216 CPDF_StreamAcc* pStreamAcc = nullptr; 1225 CPDF_StreamAcc* pStreamAcc = nullptr;
1217 if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc)) 1226 if (m_ObjectStreamMap.Lookup((void*)(uintptr_t)objnum, (void*&)pStreamAcc))
1218 return pStreamAcc; 1227 return pStreamAcc;
1219 1228
1220 const CPDF_Stream* pStream = 1229 const CPDF_Stream* pStream =
1221 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr); 1230 ToStream(m_pDocument ? m_pDocument->GetIndirectObject(objnum) : nullptr);
1222 if (!pStream) 1231 if (!pStream)
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 } 1661 }
1653 m_LastXRefOffset += dwCount; 1662 m_LastXRefOffset += dwCount;
1654 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition(); 1663 FX_POSITION pos = m_ObjectStreamMap.GetStartPosition();
1655 while (pos) { 1664 while (pos) {
1656 void* objnum; 1665 void* objnum;
1657 CPDF_StreamAcc* pStream; 1666 CPDF_StreamAcc* pStream;
1658 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream); 1667 m_ObjectStreamMap.GetNextAssoc(pos, objnum, (void*&)pStream);
1659 delete pStream; 1668 delete pStream;
1660 } 1669 }
1661 m_ObjectStreamMap.RemoveAll(); 1670 m_ObjectStreamMap.RemoveAll();
1671 m_ObjCache.clear();
1672
1662 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && 1673 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) &&
1663 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { 1674 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) {
1664 m_LastXRefOffset = 0; 1675 m_LastXRefOffset = 0;
1665 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; 1676 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum;
1666 return PDFPARSE_ERROR_FORMAT; 1677 return PDFPARSE_ERROR_FORMAT;
1667 } 1678 }
1668 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 1679 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
1669 sizeof(FX_FILESIZE), CompareFileSize); 1680 sizeof(FX_FILESIZE), CompareFileSize);
1670 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum; 1681 m_Syntax.m_MetadataObjnum = dwSaveMetadataObjnum;
1671 return PDFPARSE_ERROR_SUCCESS; 1682 return PDFPARSE_ERROR_SUCCESS;
(...skipping 3264 matching lines...) Expand 10 before | Expand all | Expand 10 after
4936 if (!m_pLinearizedDict) 4947 if (!m_pLinearizedDict)
4937 return -1; 4948 return -1;
4938 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); 4949 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H"));
4939 if (!pRange) 4950 if (!pRange)
4940 return -1; 4951 return -1;
4941 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 4952 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
4942 if (!pStreamLen) 4953 if (!pStreamLen)
4943 return -1; 4954 return -1;
4944 return pStreamLen->GetInteger(); 4955 return pStreamLen->GetInteger();
4945 } 4956 }
OLDNEW
« no previous file with comments | « core/include/fpdfapi/fpdf_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698