Commit 7bc0f1d828eccbc5a277b75aedc85b7523919f87

Authored by m-holger
1 parent 22c6b8cc

Code tidy - Clang-Tidy rule modernize-use-emplace

examples/pdf-create.cc
@@ -50,28 +50,28 @@ ImageProvider::ImageProvider(std::string const& color_space, std::string const& @@ -50,28 +50,28 @@ ImageProvider::ImageProvider(std::string const& color_space, std::string const&
50 { 50 {
51 if (color_space == "/DeviceCMYK") { 51 if (color_space == "/DeviceCMYK") {
52 j_color_space = JCS_CMYK; 52 j_color_space = JCS_CMYK;
53 - stripes.push_back(std::string("\xff\x00\x00\x00", 4));  
54 - stripes.push_back(std::string("\x00\xff\x00\x00", 4));  
55 - stripes.push_back(std::string("\x00\x00\xff\x00", 4));  
56 - stripes.push_back(std::string("\xff\x00\xff\x00", 4));  
57 - stripes.push_back(std::string("\xff\xff\x00\x00", 4));  
58 - stripes.push_back(std::string("\x00\x00\x00\xff", 4)); 53 + stripes.emplace_back("\xff\x00\x00\x00", 4);
  54 + stripes.emplace_back("\x00\xff\x00\x00", 4);
  55 + stripes.emplace_back("\x00\x00\xff\x00", 4);
  56 + stripes.emplace_back("\xff\x00\xff\x00", 4);
  57 + stripes.emplace_back("\xff\xff\x00\x00", 4);
  58 + stripes.emplace_back("\x00\x00\x00\xff", 4);
59 } else if (color_space == "/DeviceRGB") { 59 } else if (color_space == "/DeviceRGB") {
60 j_color_space = JCS_RGB; 60 j_color_space = JCS_RGB;
61 - stripes.push_back(std::string("\xff\x00\x00", 3));  
62 - stripes.push_back(std::string("\x00\xff\x00", 3));  
63 - stripes.push_back(std::string("\x00\x00\xff", 3));  
64 - stripes.push_back(std::string("\xff\x00\xff", 3));  
65 - stripes.push_back(std::string("\xff\xff\x00", 3));  
66 - stripes.push_back(std::string("\x00\x00\x00", 3)); 61 + stripes.emplace_back("\xff\x00\x00", 3);
  62 + stripes.emplace_back("\x00\xff\x00", 3);
  63 + stripes.emplace_back("\x00\x00\xff", 3);
  64 + stripes.emplace_back("\xff\x00\xff", 3);
  65 + stripes.emplace_back("\xff\xff\x00", 3);
  66 + stripes.emplace_back("\x00\x00\x00", 3);
67 } else if (color_space == "/DeviceGray") { 67 } else if (color_space == "/DeviceGray") {
68 j_color_space = JCS_GRAYSCALE; 68 j_color_space = JCS_GRAYSCALE;
69 - stripes.push_back(std::string("\xee", 1));  
70 - stripes.push_back(std::string("\xcc", 1));  
71 - stripes.push_back(std::string("\x99", 1));  
72 - stripes.push_back(std::string("\x66", 1));  
73 - stripes.push_back(std::string("\x33", 1));  
74 - stripes.push_back(std::string("\x00", 1)); 69 + stripes.emplace_back("\xee", 1);
  70 + stripes.emplace_back("\xcc", 1);
  71 + stripes.emplace_back("\x99", 1);
  72 + stripes.emplace_back("\x66", 1);
  73 + stripes.emplace_back("\x33", 1);
  74 + stripes.emplace_back("\x00", 1);
75 } 75 }
76 } 76 }
77 77
@@ -335,13 +335,13 @@ create_pdf(char const* filename) @@ -335,13 +335,13 @@ create_pdf(char const* filename)
335 ">>"_qpdf); 335 ">>"_qpdf);
336 336
337 std::vector<std::string> color_spaces; 337 std::vector<std::string> color_spaces;
338 - color_spaces.push_back("/DeviceCMYK");  
339 - color_spaces.push_back("/DeviceRGB");  
340 - color_spaces.push_back("/DeviceGray"); 338 + color_spaces.emplace_back("/DeviceCMYK");
  339 + color_spaces.emplace_back("/DeviceRGB");
  340 + color_spaces.emplace_back("/DeviceGray");
341 std::vector<std::string> filters; 341 std::vector<std::string> filters;
342 - filters.push_back("null");  
343 - filters.push_back("/DCTDecode");  
344 - filters.push_back("/RunLengthDecode"); 342 + filters.emplace_back("null");
  343 + filters.emplace_back("/DCTDecode");
  344 + filters.emplace_back("/RunLengthDecode");
345 QPDFPageDocumentHelper dh(pdf); 345 QPDFPageDocumentHelper dh(pdf);
346 for (auto const& color_space: color_spaces) { 346 for (auto const& color_space: color_spaces) {
347 for (auto const& filter: filters) { 347 for (auto const& filter: filters) {
libqpdf/JSON.cc
@@ -1282,7 +1282,7 @@ JSONParser::handleToken() @@ -1282,7 +1282,7 @@ JSONParser::handleToken()
1282 1282
1283 case ps_top: 1283 case ps_top:
1284 if (!(item.isDictionary() || item.isArray())) { 1284 if (!(item.isDictionary() || item.isArray())) {
1285 - stack.push_back({ps_done, item}); 1285 + stack.emplace_back(ps_done, item);
1286 parser_state = ps_done; 1286 parser_state = ps_done;
1287 return; 1287 return;
1288 } 1288 }
@@ -1311,7 +1311,7 @@ JSONParser::handleToken() @@ -1311,7 +1311,7 @@ JSONParser::handleToken()
1311 } 1311 }
1312 1312
1313 if (item.isDictionary() || item.isArray()) { 1313 if (item.isDictionary() || item.isArray()) {
1314 - stack.push_back({parser_state, item}); 1314 + stack.emplace_back(parser_state, item);
1315 // Calling container start method is postponed until after adding the containers to their 1315 // Calling container start method is postponed until after adding the containers to their
1316 // parent containers, if any. This makes it much easier to keep track of the current nesting 1316 // parent containers, if any. This makes it much easier to keep track of the current nesting
1317 // level. 1317 // level.
libqpdf/NNTree.cc
@@ -319,7 +319,7 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list&lt;PathElement&gt;::iterato @@ -319,7 +319,7 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list&lt;PathElement&gt;::iterato
319 auto next = this->path.begin(); 319 auto next = this->path.begin();
320 next->node = first_node; 320 next->node = first_node;
321 } 321 }
322 - this->path.push_front(PathElement(to_split, 0)); 322 + this->path.emplace_front(to_split, 0);
323 parent = this->path.begin(); 323 parent = this->path.begin();
324 to_split = first_node; 324 to_split = first_node;
325 } 325 }
@@ -578,7 +578,7 @@ NNTreeIterator::setItemNumber(QPDFObjectHandle const&amp; node, int n) @@ -578,7 +578,7 @@ NNTreeIterator::setItemNumber(QPDFObjectHandle const&amp; node, int n)
578 void 578 void
579 NNTreeIterator::addPathElement(QPDFObjectHandle const& node, int kid_number) 579 NNTreeIterator::addPathElement(QPDFObjectHandle const& node, int kid_number)
580 { 580 {
581 - this->path.push_back(PathElement(node, kid_number)); 581 + this->path.emplace_back(node, kid_number);
582 } 582 }
583 583
584 bool 584 bool
libqpdf/QPDF.cc
@@ -840,7 +840,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset) @@ -840,7 +840,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
840 } 840 }
841 if (type == 'f') { 841 if (type == 'f') {
842 // Save deleted items until after we've checked the XRefStm, if any. 842 // Save deleted items until after we've checked the XRefStm, if any.
843 - deleted_items.push_back(QPDFObjGen(toI(i), f2)); 843 + deleted_items.emplace_back(toI(i), f2);
844 } else { 844 } else {
845 insertXrefEntry(toI(i), 1, f1, f2); 845 insertXrefEntry(toI(i), 1, f1, f2);
846 } 846 }
libqpdf/QPDFAcroFormDocumentHelper.cc
@@ -165,7 +165,7 @@ QPDFAcroFormDocumentHelper::getFormFields() @@ -165,7 +165,7 @@ QPDFAcroFormDocumentHelper::getFormFields()
165 analyze(); 165 analyze();
166 std::vector<QPDFFormFieldObjectHelper> result; 166 std::vector<QPDFFormFieldObjectHelper> result;
167 for (auto const& iter: m->field_to_annotations) { 167 for (auto const& iter: m->field_to_annotations) {
168 - result.push_back(this->qpdf.getObject(iter.first)); 168 + result.emplace_back(this->qpdf.getObject(iter.first));
169 } 169 }
170 return result; 170 return result;
171 } 171 }
@@ -279,7 +279,7 @@ QPDFAcroFormDocumentHelper::analyze() @@ -279,7 +279,7 @@ QPDFAcroFormDocumentHelper::analyze()
279 annot.warnIfPossible("this widget annotation is not" 279 annot.warnIfPossible("this widget annotation is not"
280 " reachable from /AcroForm in the document catalog"); 280 " reachable from /AcroForm in the document catalog");
281 m->annotation_to_field[og] = QPDFFormFieldObjectHelper(annot); 281 m->annotation_to_field[og] = QPDFFormFieldObjectHelper(annot);
282 - m->field_to_annotations[og].push_back(QPDFAnnotationObjectHelper(annot)); 282 + m->field_to_annotations[og].emplace_back(annot);
283 } 283 }
284 } 284 }
285 } 285 }
@@ -342,7 +342,7 @@ QPDFAcroFormDocumentHelper::traverseField( @@ -342,7 +342,7 @@ QPDFAcroFormDocumentHelper::traverseField(
342 342
343 if (is_annotation) { 343 if (is_annotation) {
344 QPDFObjectHandle our_field = (is_field ? field : parent); 344 QPDFObjectHandle our_field = (is_field ? field : parent);
345 - m->field_to_annotations[our_field.getObjGen()].push_back(QPDFAnnotationObjectHelper(field)); 345 + m->field_to_annotations[our_field.getObjGen()].emplace_back(field);
346 m->annotation_to_field[og] = QPDFFormFieldObjectHelper(our_field); 346 m->annotation_to_field[og] = QPDFFormFieldObjectHelper(our_field);
347 } 347 }
348 348
libqpdf/QPDFJob.cc
@@ -2376,9 +2376,8 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea @@ -2376,9 +2376,8 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2376 2376
2377 // Read original pages from the PDF, and parse the page range associated with this 2377 // Read original pages from the PDF, and parse the page range associated with this
2378 // occurrence of the file. 2378 // occurrence of the file.
2379 - parsed_specs.push_back(  
2380 - // line-break  
2381 - QPDFPageData(page_spec.filename, page_spec_qpdfs[page_spec.filename], page_spec.range)); 2379 + parsed_specs.emplace_back(
  2380 + page_spec.filename, page_spec_qpdfs[page_spec.filename], page_spec.range);
2382 } 2381 }
2383 2382
2384 std::map<unsigned long long, bool> remove_unreferenced; 2383 std::map<unsigned long long, bool> remove_unreferenced;
@@ -2427,9 +2426,8 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea @@ -2427,9 +2426,8 @@ QPDFJob::handlePageSpecs(QPDF&amp; pdf, std::vector&lt;std::unique_ptr&lt;QPDF&gt;&gt;&amp; page_hea
2427 for (size_t j = 0; j < m->collate; ++j) { 2426 for (size_t j = 0; j < m->collate; ++j) {
2428 if (cur_page + j < page_data.selected_pages.size()) { 2427 if (cur_page + j < page_data.selected_pages.size()) {
2429 got_pages = true; 2428 got_pages = true;
2430 - new_parsed_specs.push_back(  
2431 - // line-break  
2432 - QPDFPageData(page_data, page_data.selected_pages.at(cur_page + j))); 2429 + new_parsed_specs.emplace_back(
  2430 + page_data, page_data.selected_pages.at(cur_page + j));
2433 } 2431 }
2434 } 2432 }
2435 } 2433 }
libqpdf/QPDFJob_config.cc
@@ -942,7 +942,7 @@ QPDFJob::PagesConfig* @@ -942,7 +942,7 @@ QPDFJob::PagesConfig*
942 QPDFJob::PagesConfig::pageSpec( 942 QPDFJob::PagesConfig::pageSpec(
943 std::string const& filename, std::string const& range, char const* password) 943 std::string const& filename, std::string const& range, char const* password)
944 { 944 {
945 - this->config->o.m->page_specs.push_back(QPDFJob::PageSpec(filename, password, range)); 945 + this->config->o.m->page_specs.emplace_back(filename, password, range);
946 return this; 946 return this;
947 } 947 }
948 948
libqpdf/QPDFPageDocumentHelper.cc
@@ -14,7 +14,7 @@ QPDFPageDocumentHelper::getAllPages() @@ -14,7 +14,7 @@ QPDFPageDocumentHelper::getAllPages()
14 { 14 {
15 std::vector<QPDFPageObjectHelper> pages; 15 std::vector<QPDFPageObjectHelper> pages;
16 for (auto const& iter: this->qpdf.getAllPages()) { 16 for (auto const& iter: this->qpdf.getAllPages()) {
17 - pages.push_back(QPDFPageObjectHelper(iter)); 17 + pages.emplace_back(iter);
18 } 18 }
19 return pages; 19 return pages;
20 } 20 }
libqpdf/QPDFPageObjectHelper.cc
@@ -451,7 +451,7 @@ QPDFPageObjectHelper::getAnnotations(std::string const&amp; only_subtype) @@ -451,7 +451,7 @@ QPDFPageObjectHelper::getAnnotations(std::string const&amp; only_subtype)
451 for (int i = 0; i < nannots; ++i) { 451 for (int i = 0; i < nannots; ++i) {
452 QPDFObjectHandle annot = annots.getArrayItem(i); 452 QPDFObjectHandle annot = annots.getArrayItem(i);
453 if (annot.isDictionaryOfType("", only_subtype)) { 453 if (annot.isDictionaryOfType("", only_subtype)) {
454 - result.push_back(QPDFAnnotationObjectHelper(annot)); 454 + result.emplace_back(annot);
455 } 455 }
456 } 456 }
457 } 457 }
libqpdf/QPDFParser.cc
@@ -55,7 +55,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream) @@ -55,7 +55,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
55 bool set_offset = false; 55 bool set_offset = false;
56 56
57 std::vector<StackFrame> stack; 57 std::vector<StackFrame> stack;
58 - stack.push_back(StackFrame(input)); 58 + stack.emplace_back(input);
59 std::vector<parser_state_e> state_stack; 59 std::vector<parser_state_e> state_stack;
60 state_stack.push_back(st_top); 60 state_stack.push_back(st_top);
61 qpdf_offset_t offset; 61 qpdf_offset_t offset;
@@ -141,7 +141,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream) @@ -141,7 +141,7 @@ QPDFParser::parse(bool&amp; empty, bool content_stream)
141 (tokenizer.getType() == QPDFTokenizer::tt_array_open) ? st_array 141 (tokenizer.getType() == QPDFTokenizer::tt_array_open) ? st_array
142 : st_dictionary); 142 : st_dictionary);
143 b_contents = false; 143 b_contents = false;
144 - stack.push_back(StackFrame(input)); 144 + stack.emplace_back(input);
145 } 145 }
146 break; 146 break;
147 147
libqpdf/QPDF_Array.cc
@@ -201,7 +201,7 @@ QPDF_Array::getAsVector() const @@ -201,7 +201,7 @@ QPDF_Array::getAsVector() const
201 v.reserve(size_t(size())); 201 v.reserve(size_t(size()));
202 for (auto const& item: sp_elements) { 202 for (auto const& item: sp_elements) {
203 v.resize(size_t(item.first), null_oh); 203 v.resize(size_t(item.first), null_oh);
204 - v.push_back(item.second); 204 + v.emplace_back(item.second);
205 } 205 }
206 v.resize(size_t(size()), null_oh); 206 v.resize(size_t(size()), null_oh);
207 return v; 207 return v;
libqpdf/QPDF_linearization.cc
@@ -1367,7 +1367,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1367,7 +1367,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1367 for (auto& oh: m->part6) { 1367 for (auto& oh: m->part6) {
1368 int obj = oh.getObjectID(); 1368 int obj = oh.getObjectID();
1369 obj_to_index[obj] = toI(shared.size()); 1369 obj_to_index[obj] = toI(shared.size());
1370 - shared.push_back(CHSharedObjectEntry(obj)); 1370 + shared.emplace_back(obj);
1371 } 1371 }
1372 QTC::TC("qpdf", "QPDF lin part 8 empty", m->part8.empty() ? 1 : 0); 1372 QTC::TC("qpdf", "QPDF lin part 8 empty", m->part8.empty() ? 1 : 0);
1373 if (!m->part8.empty()) { 1373 if (!m->part8.empty()) {
@@ -1375,7 +1375,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data) @@ -1375,7 +1375,7 @@ QPDF::calculateLinearizationData(std::map&lt;int, int&gt; const&amp; object_stream_data)
1375 for (auto& oh: m->part8) { 1375 for (auto& oh: m->part8) {
1376 int obj = oh.getObjectID(); 1376 int obj = oh.getObjectID();
1377 obj_to_index[obj] = toI(shared.size()); 1377 obj_to_index[obj] = toI(shared.size());
1378 - shared.push_back(CHSharedObjectEntry(obj)); 1378 + shared.emplace_back(obj);
1379 } 1379 }
1380 } 1380 }
1381 if (static_cast<size_t>(m->c_shared_object_data.nshared_total) != 1381 if (static_cast<size_t>(m->c_shared_object_data.nshared_total) !=
@@ -1585,7 +1585,7 @@ QPDF::calculateHSharedObject( @@ -1585,7 +1585,7 @@ QPDF::calculateHSharedObject(
1585 int length = outputLengthNextN(csoe.at(i).object, 1, lengths, obj_renumber); 1585 int length = outputLengthNextN(csoe.at(i).object, 1, lengths, obj_renumber);
1586 min_length = std::min(min_length, length); 1586 min_length = std::min(min_length, length);
1587 max_length = std::max(max_length, length); 1587 max_length = std::max(max_length, length);
1588 - soe.push_back(HSharedObjectEntry()); 1588 + soe.emplace_back();
1589 soe.at(i).delta_group_length = length; 1589 soe.at(i).delta_group_length = length;
1590 } 1590 }
1591 if (soe.size() != toS(cso.nshared_total)) { 1591 if (soe.size() != toS(cso.nshared_total)) {
libqpdf/QUtil.cc
@@ -1246,7 +1246,7 @@ QUtil::read_lines_from_file( @@ -1246,7 +1246,7 @@ QUtil::read_lines_from_file(
1246 char c; 1246 char c;
1247 while (next_char(c)) { 1247 while (next_char(c)) {
1248 if (buf == nullptr) { 1248 if (buf == nullptr) {
1249 - lines.push_back(""); 1249 + lines.emplace_back("");
1250 buf = &(lines.back()); 1250 buf = &(lines.back());
1251 buf->reserve(80); 1251 buf->reserve(80);
1252 } 1252 }
libqpdf/qpdf-c.cc
@@ -813,13 +813,13 @@ trap_oh_errors(qpdf_data qpdf, std::function&lt;RET()&gt; fallback, std::function&lt;RET( @@ -813,13 +813,13 @@ trap_oh_errors(qpdf_data qpdf, std::function&lt;RET()&gt; fallback, std::function&lt;RET(
813 if (!qpdf->silence_errors) { 813 if (!qpdf->silence_errors) {
814 QTC::TC("qpdf", "qpdf-c warn about oh error", qpdf->oh_error_occurred ? 0 : 1); 814 QTC::TC("qpdf", "qpdf-c warn about oh error", qpdf->oh_error_occurred ? 0 : 1);
815 if (!qpdf->oh_error_occurred) { 815 if (!qpdf->oh_error_occurred) {
816 - qpdf->warnings.push_back(QPDFExc( 816 + qpdf->warnings.emplace_back(
817 qpdf_e_internal, 817 qpdf_e_internal,
818 qpdf->qpdf->getFilename(), 818 qpdf->qpdf->getFilename(),
819 "", 819 "",
820 0, 820 0,
821 "C API function caught an exception that it isn't returning; please point the " 821 "C API function caught an exception that it isn't returning; please point the "
822 - "application developer to ERROR HANDLING in qpdf-c.h")); 822 + "application developer to ERROR HANDLING in qpdf-c.h");
823 qpdf->oh_error_occurred = true; 823 qpdf->oh_error_occurred = true;
824 } 824 }
825 *QPDFLogger::defaultLogger()->getError() << qpdf->error->what() << "\n"; 825 *QPDFLogger::defaultLogger()->getError() << qpdf->error->what() << "\n";