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

This commit is contained in:
m-holger 2023-05-27 23:49:18 +01:00
parent 22c6b8ccbc
commit 7bc0f1d828
14 changed files with 48 additions and 50 deletions

View File

@ -50,28 +50,28 @@ ImageProvider::ImageProvider(std::string const& color_space, std::string const&
{
if (color_space == "/DeviceCMYK") {
j_color_space = JCS_CMYK;
stripes.push_back(std::string("\xff\x00\x00\x00", 4));
stripes.push_back(std::string("\x00\xff\x00\x00", 4));
stripes.push_back(std::string("\x00\x00\xff\x00", 4));
stripes.push_back(std::string("\xff\x00\xff\x00", 4));
stripes.push_back(std::string("\xff\xff\x00\x00", 4));
stripes.push_back(std::string("\x00\x00\x00\xff", 4));
stripes.emplace_back("\xff\x00\x00\x00", 4);
stripes.emplace_back("\x00\xff\x00\x00", 4);
stripes.emplace_back("\x00\x00\xff\x00", 4);
stripes.emplace_back("\xff\x00\xff\x00", 4);
stripes.emplace_back("\xff\xff\x00\x00", 4);
stripes.emplace_back("\x00\x00\x00\xff", 4);
} else if (color_space == "/DeviceRGB") {
j_color_space = JCS_RGB;
stripes.push_back(std::string("\xff\x00\x00", 3));
stripes.push_back(std::string("\x00\xff\x00", 3));
stripes.push_back(std::string("\x00\x00\xff", 3));
stripes.push_back(std::string("\xff\x00\xff", 3));
stripes.push_back(std::string("\xff\xff\x00", 3));
stripes.push_back(std::string("\x00\x00\x00", 3));
stripes.emplace_back("\xff\x00\x00", 3);
stripes.emplace_back("\x00\xff\x00", 3);
stripes.emplace_back("\x00\x00\xff", 3);
stripes.emplace_back("\xff\x00\xff", 3);
stripes.emplace_back("\xff\xff\x00", 3);
stripes.emplace_back("\x00\x00\x00", 3);
} else if (color_space == "/DeviceGray") {
j_color_space = JCS_GRAYSCALE;
stripes.push_back(std::string("\xee", 1));
stripes.push_back(std::string("\xcc", 1));
stripes.push_back(std::string("\x99", 1));
stripes.push_back(std::string("\x66", 1));
stripes.push_back(std::string("\x33", 1));
stripes.push_back(std::string("\x00", 1));
stripes.emplace_back("\xee", 1);
stripes.emplace_back("\xcc", 1);
stripes.emplace_back("\x99", 1);
stripes.emplace_back("\x66", 1);
stripes.emplace_back("\x33", 1);
stripes.emplace_back("\x00", 1);
}
}
@ -335,13 +335,13 @@ create_pdf(char const* filename)
">>"_qpdf);
std::vector<std::string> color_spaces;
color_spaces.push_back("/DeviceCMYK");
color_spaces.push_back("/DeviceRGB");
color_spaces.push_back("/DeviceGray");
color_spaces.emplace_back("/DeviceCMYK");
color_spaces.emplace_back("/DeviceRGB");
color_spaces.emplace_back("/DeviceGray");
std::vector<std::string> filters;
filters.push_back("null");
filters.push_back("/DCTDecode");
filters.push_back("/RunLengthDecode");
filters.emplace_back("null");
filters.emplace_back("/DCTDecode");
filters.emplace_back("/RunLengthDecode");
QPDFPageDocumentHelper dh(pdf);
for (auto const& color_space: color_spaces) {
for (auto const& filter: filters) {

View File

@ -1282,7 +1282,7 @@ JSONParser::handleToken()
case ps_top:
if (!(item.isDictionary() || item.isArray())) {
stack.push_back({ps_done, item});
stack.emplace_back(ps_done, item);
parser_state = ps_done;
return;
}
@ -1311,7 +1311,7 @@ JSONParser::handleToken()
}
if (item.isDictionary() || item.isArray()) {
stack.push_back({parser_state, item});
stack.emplace_back(parser_state, item);
// Calling container start method is postponed until after adding the containers to their
// parent containers, if any. This makes it much easier to keep track of the current nesting
// level.

View File

@ -319,7 +319,7 @@ NNTreeIterator::split(QPDFObjectHandle to_split, std::list<PathElement>::iterato
auto next = this->path.begin();
next->node = first_node;
}
this->path.push_front(PathElement(to_split, 0));
this->path.emplace_front(to_split, 0);
parent = this->path.begin();
to_split = first_node;
}
@ -578,7 +578,7 @@ NNTreeIterator::setItemNumber(QPDFObjectHandle const& node, int n)
void
NNTreeIterator::addPathElement(QPDFObjectHandle const& node, int kid_number)
{
this->path.push_back(PathElement(node, kid_number));
this->path.emplace_back(node, kid_number);
}
bool

View File

@ -840,7 +840,7 @@ QPDF::read_xrefTable(qpdf_offset_t xref_offset)
}
if (type == 'f') {
// Save deleted items until after we've checked the XRefStm, if any.
deleted_items.push_back(QPDFObjGen(toI(i), f2));
deleted_items.emplace_back(toI(i), f2);
} else {
insertXrefEntry(toI(i), 1, f1, f2);
}

View File

@ -165,7 +165,7 @@ QPDFAcroFormDocumentHelper::getFormFields()
analyze();
std::vector<QPDFFormFieldObjectHelper> result;
for (auto const& iter: m->field_to_annotations) {
result.push_back(this->qpdf.getObject(iter.first));
result.emplace_back(this->qpdf.getObject(iter.first));
}
return result;
}
@ -279,7 +279,7 @@ QPDFAcroFormDocumentHelper::analyze()
annot.warnIfPossible("this widget annotation is not"
" reachable from /AcroForm in the document catalog");
m->annotation_to_field[og] = QPDFFormFieldObjectHelper(annot);
m->field_to_annotations[og].push_back(QPDFAnnotationObjectHelper(annot));
m->field_to_annotations[og].emplace_back(annot);
}
}
}
@ -342,7 +342,7 @@ QPDFAcroFormDocumentHelper::traverseField(
if (is_annotation) {
QPDFObjectHandle our_field = (is_field ? field : parent);
m->field_to_annotations[our_field.getObjGen()].push_back(QPDFAnnotationObjectHelper(field));
m->field_to_annotations[our_field.getObjGen()].emplace_back(field);
m->annotation_to_field[og] = QPDFFormFieldObjectHelper(our_field);
}

View File

@ -2376,9 +2376,8 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_hea
// Read original pages from the PDF, and parse the page range associated with this
// occurrence of the file.
parsed_specs.push_back(
// line-break
QPDFPageData(page_spec.filename, page_spec_qpdfs[page_spec.filename], page_spec.range));
parsed_specs.emplace_back(
page_spec.filename, page_spec_qpdfs[page_spec.filename], page_spec.range);
}
std::map<unsigned long long, bool> remove_unreferenced;
@ -2427,9 +2426,8 @@ QPDFJob::handlePageSpecs(QPDF& pdf, std::vector<std::unique_ptr<QPDF>>& page_hea
for (size_t j = 0; j < m->collate; ++j) {
if (cur_page + j < page_data.selected_pages.size()) {
got_pages = true;
new_parsed_specs.push_back(
// line-break
QPDFPageData(page_data, page_data.selected_pages.at(cur_page + j)));
new_parsed_specs.emplace_back(
page_data, page_data.selected_pages.at(cur_page + j));
}
}
}

View File

@ -942,7 +942,7 @@ QPDFJob::PagesConfig*
QPDFJob::PagesConfig::pageSpec(
std::string const& filename, std::string const& range, char const* password)
{
this->config->o.m->page_specs.push_back(QPDFJob::PageSpec(filename, password, range));
this->config->o.m->page_specs.emplace_back(filename, password, range);
return this;
}

View File

@ -14,7 +14,7 @@ QPDFPageDocumentHelper::getAllPages()
{
std::vector<QPDFPageObjectHelper> pages;
for (auto const& iter: this->qpdf.getAllPages()) {
pages.push_back(QPDFPageObjectHelper(iter));
pages.emplace_back(iter);
}
return pages;
}

View File

@ -451,7 +451,7 @@ QPDFPageObjectHelper::getAnnotations(std::string const& only_subtype)
for (int i = 0; i < nannots; ++i) {
QPDFObjectHandle annot = annots.getArrayItem(i);
if (annot.isDictionaryOfType("", only_subtype)) {
result.push_back(QPDFAnnotationObjectHelper(annot));
result.emplace_back(annot);
}
}
}

View File

@ -55,7 +55,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
bool set_offset = false;
std::vector<StackFrame> stack;
stack.push_back(StackFrame(input));
stack.emplace_back(input);
std::vector<parser_state_e> state_stack;
state_stack.push_back(st_top);
qpdf_offset_t offset;
@ -141,7 +141,7 @@ QPDFParser::parse(bool& empty, bool content_stream)
(tokenizer.getType() == QPDFTokenizer::tt_array_open) ? st_array
: st_dictionary);
b_contents = false;
stack.push_back(StackFrame(input));
stack.emplace_back(input);
}
break;

View File

@ -201,7 +201,7 @@ QPDF_Array::getAsVector() const
v.reserve(size_t(size()));
for (auto const& item: sp_elements) {
v.resize(size_t(item.first), null_oh);
v.push_back(item.second);
v.emplace_back(item.second);
}
v.resize(size_t(size()), null_oh);
return v;

View File

@ -1367,7 +1367,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
for (auto& oh: m->part6) {
int obj = oh.getObjectID();
obj_to_index[obj] = toI(shared.size());
shared.push_back(CHSharedObjectEntry(obj));
shared.emplace_back(obj);
}
QTC::TC("qpdf", "QPDF lin part 8 empty", m->part8.empty() ? 1 : 0);
if (!m->part8.empty()) {
@ -1375,7 +1375,7 @@ QPDF::calculateLinearizationData(std::map<int, int> const& object_stream_data)
for (auto& oh: m->part8) {
int obj = oh.getObjectID();
obj_to_index[obj] = toI(shared.size());
shared.push_back(CHSharedObjectEntry(obj));
shared.emplace_back(obj);
}
}
if (static_cast<size_t>(m->c_shared_object_data.nshared_total) !=
@ -1585,7 +1585,7 @@ QPDF::calculateHSharedObject(
int length = outputLengthNextN(csoe.at(i).object, 1, lengths, obj_renumber);
min_length = std::min(min_length, length);
max_length = std::max(max_length, length);
soe.push_back(HSharedObjectEntry());
soe.emplace_back();
soe.at(i).delta_group_length = length;
}
if (soe.size() != toS(cso.nshared_total)) {

View File

@ -1246,7 +1246,7 @@ QUtil::read_lines_from_file(
char c;
while (next_char(c)) {
if (buf == nullptr) {
lines.push_back("");
lines.emplace_back("");
buf = &(lines.back());
buf->reserve(80);
}

View File

@ -813,13 +813,13 @@ trap_oh_errors(qpdf_data qpdf, std::function<RET()> fallback, std::function<RET(
if (!qpdf->silence_errors) {
QTC::TC("qpdf", "qpdf-c warn about oh error", qpdf->oh_error_occurred ? 0 : 1);
if (!qpdf->oh_error_occurred) {
qpdf->warnings.push_back(QPDFExc(
qpdf->warnings.emplace_back(
qpdf_e_internal,
qpdf->qpdf->getFilename(),
"",
0,
"C API function caught an exception that it isn't returning; please point the "
"application developer to ERROR HANDLING in qpdf-c.h"));
"application developer to ERROR HANDLING in qpdf-c.h");
qpdf->oh_error_occurred = true;
}
*QPDFLogger::defaultLogger()->getError() << qpdf->error->what() << "\n";