Commit 5ad81ce6049b685694c59c9c155314c99f6f2303

Authored by m-holger
1 parent bd197adf

Refactor `QPDF::getAllPages` usage: replace with `Pages::all` across `Doc::Linearization`.

Showing 1 changed file with 21 additions and 21 deletions
libqpdf/QPDF_linearization.cc
... ... @@ -189,7 +189,7 @@ Lin::readLinearizationData()
189 189 // Various places in the code use linp.npages, which is initialized from N, to pre-allocate
190 190 // memory, so make sure it's accurate and bail right now if it's not.
191 191 no_ci_stop_if(
192   - N != qpdf.getAllPages().size(),
  192 + N != pages.size(),
193 193 "/N does not match number of pages",
194 194 "linearization dictionary" //
195 195 );
... ... @@ -390,20 +390,20 @@ Lin::checkLinearizationInternal()
390 390 // L: file size in bytes -- checked by isLinearized
391 391  
392 392 // O: object number of first page
393   - std::vector<QPDFObjectHandle> const& pages = qpdf.getAllPages();
394   - if (p.first_page_object != pages.at(0).getObjectID()) {
  393 + auto const& all_pages = pages.all();
  394 + if (p.first_page_object != all_pages.at(0).getObjectID()) {
395 395 linearizationWarning("first page object (/O) mismatch");
396 396 }
397 397  
398 398 // N: number of pages
399   - size_t npages = pages.size();
  399 + size_t npages = all_pages.size();
400 400 if (std::cmp_not_equal(p.npages, npages)) {
401 401 // Not tested in the test suite
402 402 linearizationWarning("page count (/N) mismatch");
403 403 }
404 404  
405 405 int i = 0;
406   - for (auto const& page: pages) {
  406 + for (auto const& page: all_pages) {
407 407 if (m->xref_table[page].getType() == 2) {
408 408 linearizationWarning(
409 409 "page dictionary for page " + std::to_string(i) + " is compressed");
... ... @@ -485,8 +485,8 @@ Lin::checkLinearizationInternal()
485 485 // Check hint tables
486 486  
487 487 std::map<int, int> shared_idx_to_obj;
488   - checkHSharedObject(pages, shared_idx_to_obj);
489   - checkHPageOffset(pages, shared_idx_to_obj);
  488 + checkHSharedObject(all_pages, shared_idx_to_obj);
  489 + checkHPageOffset(all_pages, shared_idx_to_obj);
490 490 checkHOutlines();
491 491 }
492 492  
... ... @@ -1104,12 +1104,12 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data)
1104 1104  
1105 1105 // We seem to traverse the page tree a lot in this code, but we can address this for a future
1106 1106 // code optimization if necessary. Premature optimization is the root of all evil.
1107   - std::vector<QPDFObjectHandle> pages;
  1107 + std::vector<QPDFObjectHandle> uc_pages;
1108 1108 { // local scope
1109 1109 // Map all page objects to the containing object stream. This should be a no-op in a
1110 1110 // properly linearized file.
1111   - for (auto oh: qpdf.getAllPages()) {
1112   - pages.emplace_back(getUncompressedObject(oh, object_stream_data));
  1111 + for (auto oh: pages.all()) {
  1112 + uc_pages.emplace_back(getUncompressedObject(oh, object_stream_data));
1113 1113 }
1114 1114 }
1115 1115 size_t npages = pages.size();
... ... @@ -1144,12 +1144,12 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data)
1144 1144 no_ci_stop_if(
1145 1145 pages.empty(), "no pages found while calculating linearization data" //
1146 1146 );
1147   - QPDFObjGen first_page_og(pages.at(0).getObjGen());
  1147 + QPDFObjGen first_page_og(uc_pages.at(0).getObjGen());
1148 1148 no_ci_stop_if(
1149 1149 !lc_first_page_private.erase(first_page_og), "unable to linearize first page" //
1150 1150 );
1151   - m->c_linp.first_page_object = pages.at(0).getObjectID();
1152   - m->part6.emplace_back(pages.at(0));
  1151 + m->c_linp.first_page_object = uc_pages.at(0).getObjectID();
  1152 + m->part6.emplace_back(uc_pages.at(0));
1153 1153  
1154 1154 // The PDF spec "recommends" an order for the rest of the objects, but we are going to disregard
1155 1155 // it except to the extent that it groups private and shared objects contiguously for the sake
... ... @@ -1180,13 +1180,13 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data)
1180 1180 for (size_t i = 1; i < npages; ++i) {
1181 1181 // Place this page's page object
1182 1182  
1183   - QPDFObjGen page_og(pages.at(i).getObjGen());
  1183 + QPDFObjGen page_og(uc_pages.at(i).getObjGen());
1184 1184 no_ci_stop_if(
1185 1185 !lc_other_page_private.erase(page_og),
1186 1186 "unable to linearize page " + std::to_string(i) //
1187 1187 );
1188 1188  
1189   - m->part7.emplace_back(pages.at(i));
  1189 + m->part7.emplace_back(uc_pages.at(i));
1190 1190  
1191 1191 // Place all non-shared objects referenced by this page, updating the page object count for
1192 1192 // the hint table.
... ... @@ -1242,7 +1242,7 @@ Lin::calculateLinearizationData(T const&amp; object_stream_data)
1242 1242 // Place private thumbnail images in page order. Slightly more information would be required if
1243 1243 // we were going to bother with thumbnail hint tables.
1244 1244 for (size_t i = 0; i < npages; ++i) {
1245   - QPDFObjectHandle thumb = pages.at(i).getKey("/Thumb");
  1245 + QPDFObjectHandle thumb = uc_pages.at(i).getKey("/Thumb");
1246 1246 thumb = getUncompressedObject(thumb, object_stream_data);
1247 1247 QPDFObjGen thumb_og(thumb.getObjGen());
1248 1248 // Output the thumbnail itself
... ... @@ -1439,8 +1439,8 @@ Lin::calculateHPageOffset(QPDFWriter::NewObjTable const&amp; new_obj, QPDFWriter::Ob
1439 1439  
1440 1440 // We are purposely leaving some values set to their initial zero values.
1441 1441  
1442   - std::vector<QPDFObjectHandle> const& pages = qpdf.getAllPages();
1443   - size_t npages = pages.size();
  1442 + auto const& all_pages = pages.all();
  1443 + size_t npages = all_pages.size();
1444 1444 CHPageOffset& cph = m->c_page_offset_data;
1445 1445 std::vector<CHPageOffsetEntry>& cphe = cph.entries;
1446 1446  
... ... @@ -1466,7 +1466,7 @@ Lin::calculateHPageOffset(QPDFWriter::NewObjTable const&amp; new_obj, QPDFWriter::Ob
1466 1466 // assignments.
1467 1467  
1468 1468 int nobjects = cphe.at(i).nobjects;
1469   - int length = outputLengthNextN(pages.at(i).getObjectID(), nobjects, new_obj, obj);
  1469 + int length = outputLengthNextN(all_pages.at(i).getObjectID(), nobjects, new_obj, obj);
1470 1470 int nshared = cphe.at(i).nshared_objects;
1471 1471  
1472 1472 min_nobjects = std::min(min_nobjects, nobjects);
... ... @@ -1482,7 +1482,7 @@ Lin::calculateHPageOffset(QPDFWriter::NewObjTable const&amp; new_obj, QPDFWriter::Ob
1482 1482 }
1483 1483  
1484 1484 ph.min_nobjects = min_nobjects;
1485   - ph.first_page_offset = new_obj[obj[pages.at(0)].renumber].xref.getOffset();
  1485 + ph.first_page_offset = new_obj[obj[all_pages.at(0)].renumber].xref.getOffset();
1486 1486 ph.nbits_delta_nobjects = nbits(max_nobjects - min_nobjects);
1487 1487 ph.min_page_length = min_length;
1488 1488 ph.nbits_delta_page_length = nbits(max_length - min_length);
... ... @@ -1631,7 +1631,7 @@ Lin::writeHPageOffset(BitWriter&amp; w)
1631 1631 w.writeBitsInt(t.nbits_shared_numerator, 16); // 12
1632 1632 w.writeBitsInt(t.shared_denominator, 16); // 13
1633 1633  
1634   - int nitems = toI(qpdf.getAllPages().size());
  1634 + int nitems = toI(pages.size());
1635 1635 std::vector<HPageOffsetEntry>& entries = t.entries;
1636 1636  
1637 1637 write_vector_int(w, nitems, entries, t.nbits_delta_nobjects, &HPageOffsetEntry::delta_nobjects);
... ...