From: Arnaud Giersch Date: Mon, 5 Oct 2020 21:03:27 +0000 (+0200) Subject: Prefer to use emplace_back. X-Git-Tag: v3.26~378 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b60c8af597ab1859e4b804954e6e6df37e8cff06 Prefer to use emplace_back. Clang-tidy enabled checks: modernize-use-emplace --- diff --git a/examples/s4u/dht-kademlia/answer.cpp b/examples/s4u/dht-kademlia/answer.cpp index 8e3b0ab786..8a6290fc46 100644 --- a/examples/s4u/dht-kademlia/answer.cpp +++ b/examples/s4u/dht-kademlia/answer.cpp @@ -67,7 +67,7 @@ void Answer::addBucket(const Bucket* bucket) for (auto const& id : bucket->nodes_) { unsigned int distance = id ^ destination_id_; - nodes_.push_back(std::pair(id, distance)); + nodes_.emplace_back(id, distance); } } } // namespace kademlia diff --git a/examples/s4u/energy-link/s4u-energy-link.cpp b/examples/s4u/energy-link/s4u-energy-link.cpp index ff0359f568..38cad52ca8 100644 --- a/examples/s4u/energy-link/s4u-energy-link.cpp +++ b/examples/s4u/energy-link/s4u-energy-link.cpp @@ -83,11 +83,11 @@ int main(int argc, char* argv[]) std::vector argSender; std::vector argReceiver; if (argc > 2) { - argSender.push_back(argv[2]); // Take the amount of flows from the command line - argReceiver.push_back(argv[2]); + argSender.emplace_back(argv[2]); // Take the amount of flows from the command line + argReceiver.emplace_back(argv[2]); } else { - argSender.push_back("1"); // Default value - argReceiver.push_back("1"); + argSender.emplace_back("1"); // Default value + argReceiver.emplace_back("1"); } if (argc > 3) { @@ -95,10 +95,10 @@ int main(int argc, char* argv[]) std::string size = std::to_string(simgrid::xbt::random::uniform_int(min_size, max_size)); argSender.push_back(size); } else { // Not "random" ? Then it should be the size to use - argSender.push_back(argv[3]); // Take the datasize from the command line + argSender.emplace_back(argv[3]); // Take the datasize from the command line } } else { // No parameter at all? Then use the default value - argSender.push_back("25000"); + argSender.emplace_back("25000"); } simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("MyHost1"), sender, argSender); simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("MyHost2"), receiver, argReceiver); diff --git a/src/instr/jedule/jedule_events.cpp b/src/instr/jedule/jedule_events.cpp index 0211c84721..ea2dd3703e 100644 --- a/src/instr/jedule/jedule_events.cpp +++ b/src/instr/jedule/jedule_events.cpp @@ -20,7 +20,7 @@ void Event::add_resources(const std::vector& host_selection) void Event::add_characteristic(const char* characteristic) { xbt_assert( characteristic != nullptr ); - this->characteristics_list_.push_back(characteristic); + this->characteristics_list_.emplace_back(characteristic); } void Event::add_info(char* key, char* value) diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index aea322a502..d2136944e7 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -77,7 +77,7 @@ XBT_PRIVATE simgrid::kernel::activity::ActivityImplPtr simcall_HANDLER_comm_isen other_comm->clean_fun = clean_fun; } else { other_comm->clean_fun = nullptr; - src_proc->activities_.push_back(other_comm); + src_proc->activities_.emplace_back(other_comm); } /* Setup the communication synchro */ @@ -160,7 +160,7 @@ simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/, smx_actor_t receiver, smx_ other_comm->state_ = simgrid::kernel::activity::State::READY; other_comm->set_type(simgrid::kernel::activity::CommImpl::Type::READY); } - receiver->activities_.push_back(other_comm); + receiver->activities_.emplace_back(other_comm); } /* Setup communication synchro */ diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index f4ce2de60a..74129f3963 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -60,7 +60,7 @@ ExecImpl::ExecImpl() actor::ActorImpl* self = actor::ActorImpl::self(); if (self) { actor_ = self; - self->activities_.push_back(this); + self->activities_.emplace_back(this); } } diff --git a/src/kernel/resource/profile/Profile_test.cpp b/src/kernel/resource/profile/Profile_test.cpp index 5243791e2f..591b46faf3 100644 --- a/src/kernel/resource/profile/Profile_test.cpp +++ b/src/kernel/resource/profile/Profile_test.cpp @@ -53,7 +53,7 @@ static std::vector trace2vector(const char REQUIRE(it == insertedIt); // Check that we find what we've put if (value >= 0) { - res.push_back(simgrid::kernel::profile::DatedValue(thedate, value)); + res.emplace_back(thedate, value); } else { XBT_DEBUG("%.1f: ignore an event (idx: %u)\n", thedate, it->idx); } @@ -77,7 +77,7 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker std::vector got = trace2vector("9.0 3.0\n"); std::vector want; - want.push_back(simgrid::kernel::profile::DatedValue(9, 3)); + want.emplace_back(9, 3); REQUIRE(want == got); } @@ -87,8 +87,8 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker "9.0 3.0\n"); std::vector want; - want.push_back(simgrid::kernel::profile::DatedValue(3, 1)); - want.push_back(simgrid::kernel::profile::DatedValue(9, 3)); + want.emplace_back(3, 1); + want.emplace_back(9, 3); REQUIRE(want == got); } @@ -100,9 +100,9 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker "9.0 3.0\n"); std::vector want; - want.push_back(simgrid::kernel::profile::DatedValue(3, 1)); - want.push_back(simgrid::kernel::profile::DatedValue(5, 2)); - want.push_back(simgrid::kernel::profile::DatedValue(9, 3)); + want.emplace_back(3, 1); + want.emplace_back(5, 2); + want.emplace_back(9, 3); REQUIRE(want == got); } @@ -114,14 +114,14 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker "LOOPAFTER 2\n"); std::vector want; - want.push_back(simgrid::kernel::profile::DatedValue(1, 1)); - want.push_back(simgrid::kernel::profile::DatedValue(3, 3)); - want.push_back(simgrid::kernel::profile::DatedValue(6, 1)); - want.push_back(simgrid::kernel::profile::DatedValue(8, 3)); - want.push_back(simgrid::kernel::profile::DatedValue(11, 1)); - want.push_back(simgrid::kernel::profile::DatedValue(13, 3)); - want.push_back(simgrid::kernel::profile::DatedValue(16, 1)); - want.push_back(simgrid::kernel::profile::DatedValue(18, 3)); + want.emplace_back(1, 1); + want.emplace_back(3, 3); + want.emplace_back(6, 1); + want.emplace_back(8, 3); + want.emplace_back(11, 1); + want.emplace_back(13, 3); + want.emplace_back(16, 1); + want.emplace_back(18, 3); REQUIRE(want == got); } @@ -133,11 +133,11 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker "LOOPAFTER 5\n"); std::vector want; - want.push_back(simgrid::kernel::profile::DatedValue(0, 1)); - want.push_back(simgrid::kernel::profile::DatedValue(5, 2)); - want.push_back(simgrid::kernel::profile::DatedValue(10, 1)); - want.push_back(simgrid::kernel::profile::DatedValue(15, 2)); - want.push_back(simgrid::kernel::profile::DatedValue(20, 1)); + want.emplace_back(0, 1); + want.emplace_back(5, 2); + want.emplace_back(10, 1); + want.emplace_back(15, 2); + want.emplace_back(20, 1); REQUIRE(want == got); } diff --git a/src/simix/smx_deployment.cpp b/src/simix/smx_deployment.cpp index bbe3b7dbd6..54e2e62f49 100644 --- a/src/simix/smx_deployment.cpp +++ b/src/simix/smx_deployment.cpp @@ -48,12 +48,12 @@ void SIMIX_process_set_function(const char* process_host, const char* process_fu if (not host) throw std::invalid_argument(simgrid::xbt::string_printf("Host '%s' unknown", process_host)); actor.host = process_host; - actor.args.push_back(process_function); + actor.args.emplace_back(process_function); /* add arguments */ unsigned int i; char *arg; xbt_dynar_foreach(arguments, i, arg) { - actor.args.push_back(arg); + actor.args.emplace_back(arg); } // Check we know how to handle this function name: diff --git a/src/smpi/include/smpi_file.hpp b/src/smpi/include/smpi_file.hpp index 2c6139b5b8..b1d5673d93 100644 --- a/src/smpi/include/smpi_file.hpp +++ b/src/smpi/include/smpi_file.hpp @@ -144,7 +144,7 @@ int File::op_all(void* buf, int count, const Datatype* datatype, MPI_Status* sta // merge the ranges of every process std::vector> ranges; for (int i = 0; i < size; ++i) - ranges.push_back(std::make_pair(min_offsets[i], max_offsets[i])); + ranges.emplace_back(min_offsets[i], max_offsets[i]); std::sort(ranges.begin(), ranges.end()); std::vector> chunks; chunks.push_back(ranges[0]); diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 1c1d9c9914..d578f01ff2 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -172,7 +172,7 @@ void smpi_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, v } else { src_private_blocks.clear(); - src_private_blocks.push_back(std::make_pair(0, buff_size)); + src_private_blocks.emplace_back(0, buff_size); } if (smpi_is_shared((char*)comm->dst_buff_, dst_private_blocks, &dst_offset)) { dst_private_blocks = shift_and_frame_private_blocks(dst_private_blocks, dst_offset, buff_size); @@ -184,7 +184,7 @@ void smpi_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, v } else { dst_private_blocks.clear(); - dst_private_blocks.push_back(std::make_pair(0, buff_size)); + dst_private_blocks.emplace_back(0, buff_size); } check_blocks(src_private_blocks, buff_size); check_blocks(dst_private_blocks, buff_size); @@ -441,7 +441,7 @@ static void smpi_init_privatization_dlopen(const std::string& executable) #else xbt_die("smpi/privatize-libs is not (yet) compatible with OSX nor with Haiku"); #endif - privatize_libs_paths.push_back(fullpath); + privatize_libs_paths.emplace_back(fullpath); dlclose(libhandle); } } diff --git a/src/smpi/internals/smpi_replay.cpp b/src/smpi/internals/smpi_replay.cpp index 925b506073..a74f941ded 100644 --- a/src/smpi/internals/smpi_replay.cpp +++ b/src/smpi/internals/smpi_replay.cpp @@ -567,7 +567,7 @@ void WaitAllAction::kernel(simgrid::xbt::ReplayAction&) req_storage.get_requests(reqs); for (auto const& req : reqs) { if (req && (req->flags() & MPI_REQ_RECV)) { - sender_receiver.push_back({req->src(), req->dst()}); + sender_receiver.emplace_back(req->src(), req->dst()); } } Request::waitall(count_requests, &(reqs.data())[0], MPI_STATUSES_IGNORE); diff --git a/src/smpi/internals/smpi_shared.cpp b/src/smpi/internals/smpi_shared.cpp index 538a85e8ea..869f72de8f 100644 --- a/src/smpi/internals/smpi_shared.cpp +++ b/src/smpi/internals/smpi_shared.cpp @@ -287,14 +287,14 @@ void* smpi_shared_malloc_partial(size_t size, size_t* shared_block_offsets, int newmeta.allocated_ptr = allocated_ptr; newmeta.allocated_size = allocated_size; if(shared_block_offsets[0] > 0) { - newmeta.private_blocks.push_back(std::make_pair(0, shared_block_offsets[0])); + newmeta.private_blocks.emplace_back(0, shared_block_offsets[0]); } int i_block; for(i_block = 0; i_block < nb_shared_blocks-1; i_block ++) { - newmeta.private_blocks.push_back(std::make_pair(shared_block_offsets[2*i_block+1], shared_block_offsets[2*i_block+2])); + newmeta.private_blocks.emplace_back(shared_block_offsets[2 * i_block + 1], shared_block_offsets[2 * i_block + 2]); } if(shared_block_offsets[2*i_block+1] < size) { - newmeta.private_blocks.push_back(std::make_pair(shared_block_offsets[2*i_block+1], size)); + newmeta.private_blocks.emplace_back(shared_block_offsets[2 * i_block + 1], size); } allocs_metadata[mem] = newmeta; diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index e735a364f9..b7cca369c4 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -262,12 +262,12 @@ MPI_Comm Comm::split(int color, int key) for (int j = i + 1; j < size; j++) { if(recvbuf[2 * i] == recvbuf[2 * j]) { recvbuf[2 * j] = MPI_UNDEFINED; - rankmap.push_back({recvbuf[2 * j + 1], j}); + rankmap.emplace_back(recvbuf[2 * j + 1], j); } } /* Add self in the group */ recvbuf[2 * i] = MPI_UNDEFINED; - rankmap.push_back({recvbuf[2 * i + 1], i}); + rankmap.emplace_back(recvbuf[2 * i + 1], i); std::sort(begin(rankmap), end(rankmap)); group_out = new Group(rankmap.size()); if (i == 0) { diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 8e920ddbd3..f701211890 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -95,7 +95,7 @@ std::vector HostImpl::get_all_actors() { std::vector res; for (auto& actor : actor_list_) - res.push_back(actor.ciface()); + res.emplace_back(actor.ciface()); return res; } size_t HostImpl::get_actor_count() const diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index ed4fbd84c9..eebe69b783 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -849,7 +849,7 @@ void ETag_surfxml_actor() } void STag_surfxml_argument(){ - arguments.push_back(A_surfxml_argument_value); + arguments.emplace_back(A_surfxml_argument_value); } void STag_surfxml_model___prop(){ diff --git a/src/xbt/xbt_main.cpp b/src/xbt/xbt_main.cpp index 317741d265..e718a4acab 100644 --- a/src/xbt/xbt_main.cpp +++ b/src/xbt/xbt_main.cpp @@ -128,7 +128,7 @@ void xbt_init(int *argc, char **argv) simgrid::xbt::binary_name = argv[0]; for (int i = 0; i < *argc; i++) - simgrid::xbt::cmdline.push_back(argv[i]); + simgrid::xbt::cmdline.emplace_back(argv[i]); xbt_log_init(argc, argv); } diff --git a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp index 7b138ba288..fc2ca66d3a 100644 --- a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp +++ b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp @@ -173,11 +173,11 @@ int main(int argc, char* argv[]) if (argc >= 3) { argSend.clear(); - argSend.push_back(argv[2]); + argSend.emplace_back(argv[2]); } if (argc >= 4) { argRecv.clear(); - argRecv.push_back(argv[3]); + argRecv.emplace_back(argv[3]); } xbt_assert(argSend.front().size() == argRecv.front().size(), "Sender and receiver spec must be of the same size");