Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Prefer to use emplace_back.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 5 Oct 2020 21:03:27 +0000 (23:03 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 6 Oct 2020 09:24:00 +0000 (11:24 +0200)
Clang-tidy enabled checks:
    modernize-use-emplace

16 files changed:
examples/s4u/dht-kademlia/answer.cpp
examples/s4u/energy-link/s4u-energy-link.cpp
src/instr/jedule/jedule_events.cpp
src/kernel/activity/CommImpl.cpp
src/kernel/activity/ExecImpl.cpp
src/kernel/resource/profile/Profile_test.cpp
src/simix/smx_deployment.cpp
src/smpi/include/smpi_file.hpp
src/smpi/internals/smpi_global.cpp
src/smpi/internals/smpi_replay.cpp
src/smpi/internals/smpi_shared.cpp
src/smpi/mpi/smpi_comm.cpp
src/surf/HostImpl.cpp
src/surf/xml/surfxml_sax_cb.cpp
src/xbt/xbt_main.cpp
teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp

index 8e3b0ab..8a6290f 100644 (file)
@@ -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<unsigned int, unsigned int>(id, distance));
+    nodes_.emplace_back(id, distance);
   }
 }
 } // namespace kademlia
index ff0359f..38cad52 100644 (file)
@@ -83,11 +83,11 @@ int main(int argc, char* argv[])
   std::vector<std::string> argSender;
   std::vector<std::string> 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);
index 0211c84..ea2dd37 100644 (file)
@@ -20,7 +20,7 @@ void Event::add_resources(const std::vector<sg_host_t>& 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)
index aea322a..d213694 100644 (file)
@@ -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 */
index f4ce2de..74129f3 100644 (file)
@@ -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);
   }
 }
 
index 5243791..591b46f 100644 (file)
@@ -53,7 +53,7 @@ static std::vector<simgrid::kernel::profile::DatedValue> 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<simgrid::kernel::profile::DatedValue> got = trace2vector("9.0 3.0\n");
 
     std::vector<simgrid::kernel::profile::DatedValue> 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<simgrid::kernel::profile::DatedValue> 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<simgrid::kernel::profile::DatedValue> 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<simgrid::kernel::profile::DatedValue> 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<simgrid::kernel::profile::DatedValue> 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);
   }
index bbe3b7d..54e2e62 100644 (file)
@@ -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:
index 2c6139b..b1d5673 100644 (file)
@@ -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<std::pair<MPI_Offset, MPI_Offset>> 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<std::pair<MPI_Offset, MPI_Offset>> chunks;
   chunks.push_back(ranges[0]);
index 1c1d9c9..d578f01 100644 (file)
@@ -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);
     }
   }
index 925b506..a74f941 100644 (file)
@@ -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);
index 538a85e..869f72d 100644 (file)
@@ -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;
 
index e735a36..b7cca36 100644 (file)
@@ -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) {
index 8e920dd..f701211 100644 (file)
@@ -95,7 +95,7 @@ std::vector<s4u::ActorPtr> HostImpl::get_all_actors()
 {
   std::vector<s4u::ActorPtr> 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
index ed4fbd8..eebe69b 100644 (file)
@@ -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(){
index 317741d..e718a4a 100644 (file)
@@ -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);
 }
index 7b138ba..fc2ca66 100644 (file)
@@ -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");