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

Side by Side Diff: core/src/fpdfapi/fpdf_edit/fpdf_edit_create.cpp

Issue 1576113003: Use std::map in CPDF_IndirectObjects (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Remove cbegin() and cend(). Created 4 years, 11 months 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') | core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp » ('j') | 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 "core/src/fpdfapi/fpdf_edit/editint.h" 7 #include "core/src/fpdfapi/fpdf_edit/editint.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "core/include/fxcrt/fx_ext.h" 11 #include "core/include/fxcrt/fx_ext.h"
12 #include "core/include/fpdfapi/fpdf_serial.h" 12 #include "core/include/fpdfapi/fpdf_serial.h"
13 #include "core/include/fpdfapi/fpdf_parser.h" 13 #include "core/include/fpdfapi/fpdf_parser.h"
14 #include "third_party/base/stl_util.h"
14 15
15 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) 16 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024)
16 #define PDF_XREFSTREAM_MAXSIZE 10000 17 #define PDF_XREFSTREAM_MAXSIZE 10000
17 18
18 // TODO(ochang): Make helper for appending "objnum 0 R ". 19 // TODO(ochang): Make helper for appending "objnum 0 R ".
19 20
20 namespace { 21 namespace {
21 22
22 int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, 23 int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj,
23 CFX_FileBufferArchive* pFile, 24 CFX_FileBufferArchive* pFile,
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 break; 1277 break;
1277 } 1278 }
1278 } 1279 }
1279 return 1; 1280 return 1;
1280 } 1281 }
1281 int32_t CPDF_Creator::WriteOldIndirectObject(FX_DWORD objnum) { 1282 int32_t CPDF_Creator::WriteOldIndirectObject(FX_DWORD objnum) {
1282 if (m_pParser->m_V5Type[objnum] == 0 || m_pParser->m_V5Type[objnum] == 255) { 1283 if (m_pParser->m_V5Type[objnum] == 0 || m_pParser->m_V5Type[objnum] == 255) {
1283 return 0; 1284 return 0;
1284 } 1285 }
1285 m_ObjectOffset[objnum] = m_Offset; 1286 m_ObjectOffset[objnum] = m_Offset;
1286 void* valuetemp = NULL;
1287 FX_BOOL bExistInMap = 1287 FX_BOOL bExistInMap =
1288 m_pDocument->m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, valuetemp); 1288 pdfium::ContainsKey(m_pDocument->m_IndirectObjs, objnum);
1289 FX_BOOL bObjStm = 1289 FX_BOOL bObjStm =
1290 (m_pParser->m_V5Type[objnum] == 2) && m_pEncryptDict && !m_pXRefStream; 1290 (m_pParser->m_V5Type[objnum] == 2) && m_pEncryptDict && !m_pXRefStream;
1291 if (m_pParser->m_bVersionUpdated || m_bSecurityChanged || bExistInMap || 1291 if (m_pParser->m_bVersionUpdated || m_bSecurityChanged || bExistInMap ||
1292 bObjStm) { 1292 bObjStm) {
1293 CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum, nullptr); 1293 CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum, nullptr);
1294 if (!pObj) { 1294 if (!pObj) {
1295 m_ObjectOffset[objnum] = 0; 1295 m_ObjectOffset[objnum] = 0;
1296 return 0; 1296 return 0;
1297 } 1297 }
1298 if (WriteIndirectObj(pObj)) { 1298 if (WriteIndirectObj(pObj)) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 return 1; 1364 return 1;
1365 } 1365 }
1366 } 1366 }
1367 return 0; 1367 return 0;
1368 } 1368 }
1369 int32_t CPDF_Creator::WriteNewObjs(FX_BOOL bIncremental, IFX_Pause* pPause) { 1369 int32_t CPDF_Creator::WriteNewObjs(FX_BOOL bIncremental, IFX_Pause* pPause) {
1370 int32_t iCount = m_NewObjNumArray.GetSize(); 1370 int32_t iCount = m_NewObjNumArray.GetSize();
1371 int32_t index = (int32_t)(uintptr_t)m_Pos; 1371 int32_t index = (int32_t)(uintptr_t)m_Pos;
1372 while (index < iCount) { 1372 while (index < iCount) {
1373 FX_DWORD objnum = m_NewObjNumArray.ElementAt(index); 1373 FX_DWORD objnum = m_NewObjNumArray.ElementAt(index);
1374 CPDF_Object* pObj = NULL; 1374 auto it = m_pDocument->m_IndirectObjs.find(objnum);
1375 m_pDocument->m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, (void*&)pObj); 1375 if (it == m_pDocument->m_IndirectObjs.end()) {
1376 if (NULL == pObj) {
1377 ++index; 1376 ++index;
1378 continue; 1377 continue;
1379 } 1378 }
1380 m_ObjectOffset[objnum] = m_Offset; 1379 m_ObjectOffset[objnum] = m_Offset;
1381 if (WriteIndirectObj(pObj)) { 1380 if (WriteIndirectObj(it->second)) {
1382 return -1; 1381 return -1;
1383 } 1382 }
1384 index++; 1383 index++;
1385 if (pPause && pPause->NeedToPauseNow()) { 1384 if (pPause && pPause->NeedToPauseNow()) {
1386 m_Pos = (FX_POSITION)(uintptr_t)index; 1385 m_Pos = (FX_POSITION)(uintptr_t)index;
1387 return 1; 1386 return 1;
1388 } 1387 }
1389 } 1388 }
1390 return 0; 1389 return 0;
1391 } 1390 }
(...skipping 17 matching lines...) Expand all
1409 m_pParser->m_V5Type[j] != 255) { 1408 m_pParser->m_V5Type[j] != 255) {
1410 j++; 1409 j++;
1411 } 1410 }
1412 m_ObjectOffset.Add(dwStart, j - dwStart); 1411 m_ObjectOffset.Add(dwStart, j - dwStart);
1413 dwStart = j; 1412 dwStart = j;
1414 } 1413 }
1415 } 1414 }
1416 void CPDF_Creator::InitNewObjNumOffsets() { 1415 void CPDF_Creator::InitNewObjNumOffsets() {
1417 FX_BOOL bIncremental = (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; 1416 FX_BOOL bIncremental = (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0;
1418 FX_BOOL bNoOriginal = (m_dwFlags & FPDFCREATE_NO_ORIGINAL) != 0; 1417 FX_BOOL bNoOriginal = (m_dwFlags & FPDFCREATE_NO_ORIGINAL) != 0;
1419 FX_POSITION pos = m_pDocument->m_IndirectObjs.GetStartPosition(); 1418 for (const auto& pair : m_pDocument->m_IndirectObjs) {
1420 while (pos) { 1419 if (pair.second->GetObjNum() == -1)
1421 size_t key = 0; 1420 continue;
1422 CPDF_Object* pObj; 1421 if (bIncremental) {
1423 m_pDocument->m_IndirectObjs.GetNextAssoc(pos, (void*&)key, (void*&)pObj); 1422 if (!pair.second->IsModified())
1424 FX_DWORD objnum = (FX_DWORD)key; 1423 continue;
1425 if (pObj->GetObjNum() == -1) { 1424 } else if (m_pParser && m_pParser->IsValidObjectNumber(pair.first) &&
1425 m_pParser->m_V5Type[pair.first]) {
1426 continue; 1426 continue;
1427 } 1427 }
1428 if (bIncremental) { 1428 AppendNewObjNum(pair.first);
1429 if (!pObj->IsModified()) {
1430 continue;
1431 }
1432 } else if (m_pParser && m_pParser->IsValidObjectNumber(objnum) &&
1433 m_pParser->m_V5Type[objnum]) {
1434 continue;
1435 }
1436 AppendNewObjNum(objnum);
1437 } 1429 }
1438 int32_t iCount = m_NewObjNumArray.GetSize(); 1430 int32_t iCount = m_NewObjNumArray.GetSize();
1439 if (iCount == 0) { 1431 if (iCount == 0) {
1440 return; 1432 return;
1441 } 1433 }
1442 int32_t i = 0; 1434 int32_t i = 0;
1443 FX_DWORD dwStartObjNum = 0; 1435 FX_DWORD dwStartObjNum = 0;
1444 FX_BOOL bCrossRefValid = m_pParser && m_pParser->GetLastXRefOffset() > 0; 1436 FX_BOOL bCrossRefValid = m_pParser && m_pParser->GetLastXRefOffset() > 0;
1445 while (i < iCount) { 1437 while (i < iCount) {
1446 dwStartObjNum = m_NewObjNumArray.ElementAt(i); 1438 dwStartObjNum = m_NewObjNumArray.ElementAt(i);
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
2086 m_bNewCrypto = FALSE; 2078 m_bNewCrypto = FALSE;
2087 if (!m_bStandardSecurity) { 2079 if (!m_bStandardSecurity) {
2088 return; 2080 return;
2089 } 2081 }
2090 if (m_pEncryptDict) { 2082 if (m_pEncryptDict) {
2091 m_pEncryptDict->Release(); 2083 m_pEncryptDict->Release();
2092 m_pEncryptDict = NULL; 2084 m_pEncryptDict = NULL;
2093 } 2085 }
2094 m_bStandardSecurity = FALSE; 2086 m_bStandardSecurity = FALSE;
2095 } 2087 }
OLDNEW
« no previous file with comments | « core/include/fpdfapi/fpdf_parser.h ('k') | core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698