From: Arnaud Giersch Date: Mon, 7 Nov 2022 15:03:13 +0000 (+0100) Subject: Remove explicit conversion to std::string when it's not required. X-Git-Tag: v3.34~688 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4c753f8d4cabd4104f3f7109823f16be2ebdcce3 Remove explicit conversion to std::string when it's not required. Some of them were redundant. Some of them became optional after the removal of xbt::string. --- diff --git a/docs/source/Tutorial_Algorithms.rst b/docs/source/Tutorial_Algorithms.rst index 8adaa60fd0..7d9ca41ae1 100644 --- a/docs/source/Tutorial_Algorithms.rst +++ b/docs/source/Tutorial_Algorithms.rst @@ -636,8 +636,8 @@ information is only written once. It thus follows the `DRY .. code-block:: cpp for (int i = 0; i < tasks_count; i++) { - std::string worker_rank = std::to_string(i % workers_count); - std::string mailbox_name = std::string("worker-") + worker_rank; + std::string worker_rank = std::to_string(i % workers_count); + std::string mailbox_name = "worker-" + worker_rank; simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); mailbox->put(...); diff --git a/docs/source/tuto_s4u/master-workers-lab1.cpp b/docs/source/tuto_s4u/master-workers-lab1.cpp index 7b6fbb67cb..c6f879c807 100644 --- a/docs/source/tuto_s4u/master-workers-lab1.cpp +++ b/docs/source/tuto_s4u/master-workers-lab1.cpp @@ -29,9 +29,9 @@ static void master(std::vector args) for (int i = 0; i < tasks_count; i++) { /* For each task to be executed: */ /* - Select a worker in a round-robin way */ - std::string worker_rank = std::to_string(i % workers_count); - std::string mailbox_name = std::string("worker-") + worker_rank; - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + std::string worker_rank = std::to_string(i % workers_count); + std::string mailbox_name = "worker-" + worker_rank; + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); /* - Send the computation cost to that worker */ XBT_INFO("Sending task %d of %ld to mailbox '%s'", i, tasks_count, mailbox->get_cname()); @@ -41,8 +41,8 @@ static void master(std::vector args) XBT_INFO("All tasks have been dispatched. Request all workers to stop."); for (int i = 0; i < workers_count; i++) { /* The workers stop when receiving a negative compute_cost */ - std::string mailbox_name = std::string("worker-") + std::to_string(i); - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + std::string mailbox_name = "worker-" + std::to_string(i); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); mailbox->put(new double(-1.0), 0); } @@ -53,8 +53,8 @@ static void worker(std::vector args) xbt_assert(args.size() == 2, "The worker expects a single argument"); long id = std::stol(args[1]); - const std::string mailbox_name = std::string("worker-") + std::to_string(id); - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + const std::string mailbox_name = "worker-" + std::to_string(id); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); double compute_cost; do { diff --git a/docs/source/tuto_s4u/master-workers-lab2.cpp b/docs/source/tuto_s4u/master-workers-lab2.cpp index 231a705eca..39faad2a47 100644 --- a/docs/source/tuto_s4u/master-workers-lab2.cpp +++ b/docs/source/tuto_s4u/master-workers-lab2.cpp @@ -18,8 +18,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_masterworker, "Messages specific for this e static void worker() { - const std::string mailbox_name = std::string("worker-") + std::to_string(simgrid::s4u::this_actor::get_pid()); - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + const std::string mailbox_name = "worker-" + std::to_string(simgrid::s4u::this_actor::get_pid()); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); double compute_cost; do { @@ -45,7 +45,7 @@ static void master(std::vector args) std::vector actors; for (auto* host : simgrid::s4u::Engine::get_instance()->get_all_hosts()) { - simgrid::s4u::ActorPtr act = simgrid::s4u::Actor::create(std::string("Worker-") + host->get_name(), host, worker); + simgrid::s4u::ActorPtr act = simgrid::s4u::Actor::create("Worker-" + host->get_name(), host, worker); actors.push_back(act); } @@ -53,9 +53,9 @@ static void master(std::vector args) for (int i = 0; i < tasks_count; i++) { /* For each task to be executed: */ /* - Select a worker in a round-robin way */ - aid_t worker_pid = actors.at(i % actors.size())->get_pid(); - std::string mailbox_name = std::string("worker-") + std::to_string(worker_pid); - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + aid_t worker_pid = actors.at(i % actors.size())->get_pid(); + std::string mailbox_name = "worker-" + std::to_string(worker_pid); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); /* - Send the computation cost to that worker */ XBT_INFO("Sending task %d of %ld to mailbox '%s'", i, tasks_count, mailbox->get_cname()); @@ -65,8 +65,8 @@ static void master(std::vector args) XBT_INFO("All tasks have been dispatched. Request all workers to stop."); for (unsigned long i = 0; i < actors.size(); i++) { /* The workers stop when receiving a negative compute_cost */ - std::string mailbox_name = std::string("worker-") + std::to_string(actors.at(i)->get_pid()); - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + std::string mailbox_name = "worker-" + std::to_string(actors.at(i)->get_pid()); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); mailbox->put(new double(-1.0), 0); } diff --git a/docs/source/tuto_s4u/master-workers-lab3.cpp b/docs/source/tuto_s4u/master-workers-lab3.cpp index 2f10f58f0f..e1f44a14a3 100644 --- a/docs/source/tuto_s4u/master-workers-lab3.cpp +++ b/docs/source/tuto_s4u/master-workers-lab3.cpp @@ -18,8 +18,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_masterworker, "Messages specific for this e static void worker() { - const std::string mailbox_name = std::string("worker-") + std::to_string(simgrid::s4u::this_actor::get_pid()); - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + const std::string mailbox_name = "worker-" + std::to_string(simgrid::s4u::this_actor::get_pid()); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); while (true) { // Master forcefully kills the workers by the end of the simulation double* msg = mailbox->get(); @@ -45,16 +45,16 @@ static void master(std::vector args) XBT_INFO("Asked to run for %.1f seconds", simulation_duration); for (auto* host : e->get_all_hosts()) { - simgrid::s4u::ActorPtr act = simgrid::s4u::Actor::create(std::string("Worker-") + host->get_name(), host, worker); + simgrid::s4u::ActorPtr act = simgrid::s4u::Actor::create("Worker-" + host->get_name(), host, worker); actors.push_back(act); } int task_id = 0; while (simgrid::s4u::Engine::get_clock() < simulation_duration) { /* For each task: */ /* - Select a worker in a round-robin way */ - aid_t worker_pid = actors.at(task_id % actors.size())->get_pid(); - std::string mailbox_name = std::string("worker-") + std::to_string(worker_pid); - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + aid_t worker_pid = actors.at(task_id % actors.size())->get_pid(); + std::string mailbox_name = "worker-" + std::to_string(worker_pid); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); /* - Send the computation cost to that worker */ if (task_id % 100 == 0) diff --git a/docs/source/tuto_s4u/master-workers-lab4.cpp b/docs/source/tuto_s4u/master-workers-lab4.cpp index 3cc8ff2657..6973e696e5 100644 --- a/docs/source/tuto_s4u/master-workers-lab4.cpp +++ b/docs/source/tuto_s4u/master-workers-lab4.cpp @@ -18,8 +18,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_app_masterworker, "Messages specific for this e static void worker(std::string category) { - const std::string mailbox_name = std::string("worker-") + std::to_string(simgrid::s4u::this_actor::get_pid()); - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + const std::string mailbox_name = "worker-" + std::to_string(simgrid::s4u::this_actor::get_pid()); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); while (true) { // Master forcefully kills the workers by the end of the simulation double* msg = mailbox->get(); @@ -45,22 +45,21 @@ static void master(std::vector args) std::vector actors; simgrid::s4u::Engine* e = simgrid::s4u::Engine::get_instance(); - std::string my_name = std::string("master-") + std::to_string(simgrid::s4u::this_actor::get_pid()); + std::string my_name = "master-" + std::to_string(simgrid::s4u::this_actor::get_pid()); XBT_INFO("Asked to run for %.1f seconds", simulation_duration); for (auto* host : e->get_all_hosts()) { - simgrid::s4u::ActorPtr act = - simgrid::s4u::Actor::create(std::string("Worker-") + host->get_name(), host, worker, my_name); + simgrid::s4u::ActorPtr act = simgrid::s4u::Actor::create("Worker-" + host->get_name(), host, worker, my_name); actors.push_back(act); } int task_id = 0; while (simgrid::s4u::Engine::get_clock() < simulation_duration) { /* For each task: */ /* - Select a worker in a round-robin way */ - aid_t worker_pid = actors.at(task_id % actors.size())->get_pid(); - std::string mailbox_name = std::string("worker-") + std::to_string(worker_pid); - simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); + aid_t worker_pid = actors.at(task_id % actors.size())->get_pid(); + std::string mailbox_name = "worker-" + std::to_string(worker_pid); + simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name(mailbox_name); /* - Send the computation cost to that worker */ XBT_DEBUG("Sending task %d to mailbox '%s'", task_id, mailbox->get_cname()); diff --git a/examples/cpp/activity-testany/s4u-activity-testany.cpp b/examples/cpp/activity-testany/s4u-activity-testany.cpp index 6dc8769d28..5a8a651ea6 100644 --- a/examples/cpp/activity-testany/s4u-activity-testany.cpp +++ b/examples/cpp/activity-testany/s4u-activity-testany.cpp @@ -13,7 +13,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_activity_testany, "Messages specific for this s static void bob() { - sg4::Mailbox* mbox = sg4::Mailbox::by_name(std::string("mbox")); + sg4::Mailbox* mbox = sg4::Mailbox::by_name("mbox"); const sg4::Disk* disk = sg4::Host::current()->get_disks().front(); std::string* payload; @@ -54,7 +54,7 @@ static void alice() { auto* payload = new std::string("Message"); XBT_INFO("Send '%s'", payload->c_str()); - sg4::Mailbox::by_name(std::string("mbox"))->put(payload, 6e8); + sg4::Mailbox::by_name("mbox")->put(payload, 6e8); } int main(int argc, char* argv[]) diff --git a/examples/cpp/activity-waitany/s4u-activity-waitany.cpp b/examples/cpp/activity-waitany/s4u-activity-waitany.cpp index aa13b415dc..83a6842f9d 100644 --- a/examples/cpp/activity-waitany/s4u-activity-waitany.cpp +++ b/examples/cpp/activity-waitany/s4u-activity-waitany.cpp @@ -13,7 +13,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_activity_waittany, "Messages specific for this static void bob() { - sg4::Mailbox* mbox = sg4::Mailbox::by_name(std::string("mbox")); + sg4::Mailbox* mbox = sg4::Mailbox::by_name("mbox"); const sg4::Disk* disk = sg4::Host::current()->get_disks().front(); std::string* payload; @@ -48,7 +48,7 @@ static void alice() { auto* payload = new std::string("Message"); XBT_INFO("Send '%s'", payload->c_str()); - sg4::Mailbox::by_name(std::string("mbox"))->put(payload, 6e8); + sg4::Mailbox::by_name("mbox")->put(payload, 6e8); } int main(int argc, char* argv[]) diff --git a/examples/cpp/app-chainsend/s4u-app-chainsend.cpp b/examples/cpp/app-chainsend/s4u-app-chainsend.cpp index bddfeb45c3..27484ce52e 100644 --- a/examples/cpp/app-chainsend/s4u-app-chainsend.cpp +++ b/examples/cpp/app-chainsend/s4u-app-chainsend.cpp @@ -123,7 +123,7 @@ public: Broadcaster(int hostcount, unsigned int piece_count) : piece_count(piece_count) { for (int i = 1; i <= hostcount; i++) { - std::string name = std::string("node-") + std::to_string(i) + ".simgrid.org"; + std::string name = "node-" + std::to_string(i) + ".simgrid.org"; XBT_DEBUG("%s", name.c_str()); mailboxes.push_back(sg4::Mailbox::by_name(name)); } diff --git a/examples/cpp/cloud-simple/s4u-cloud-simple.cpp b/examples/cpp/cloud-simple/s4u-cloud-simple.cpp index 9c5134c7a9..90373f11ee 100644 --- a/examples/cpp/cloud-simple/s4u-cloud-simple.cpp +++ b/examples/cpp/cloud-simple/s4u-cloud-simple.cpp @@ -57,7 +57,7 @@ static void communication_rx_fun(std::vector args) static void launch_communication_worker(s4u_Host* tx_host, s4u_Host* rx_host) { - std::string mbox_name = std::string("MBOX:") + tx_host->get_cname() + "-" + rx_host->get_cname(); + std::string mbox_name = "MBOX:" + tx_host->get_name() + "-" + rx_host->get_name(); std::vector args; args.push_back(mbox_name); diff --git a/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp b/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp index 8ae7a7a03c..db613f67ca 100644 --- a/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp +++ b/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp @@ -30,8 +30,7 @@ public: std::vector mboxes; /* Start dispatching 1 message to all receivers */ - std::string msg_content = - std::string("Hello, I'm alive and running on ") + std::string(sg4::this_actor::get_host()->get_name()); + std::string msg_content = "Hello, I'm alive and running on " + sg4::this_actor::get_host()->get_name(); for (const auto* host : hosts_) { /* Copy the data we send: the 'msg_content' variable is not a stable storage location. * It will be destroyed when this actor leaves the loop, ie before the receiver gets it */ @@ -307,7 +306,7 @@ int main(int argc, char* argv[]) sg4::Actor::create("sender", host_list[0], Sender(host_list)); /* create receiver in every host */ for (auto* host : host_list) { - sg4::Actor::create(std::string("receiver-") + std::string(host->get_name()), host, Receiver()); + sg4::Actor::create("receiver-" + host->get_name(), host, Receiver()); } /* runs the simulation */ diff --git a/examples/cpp/comm-ready/s4u-comm-ready.cpp b/examples/cpp/comm-ready/s4u-comm-ready.cpp index edb9575f49..d90d52de36 100644 --- a/examples/cpp/comm-ready/s4u-comm-ready.cpp +++ b/examples/cpp/comm-ready/s4u-comm-ready.cpp @@ -30,7 +30,7 @@ static void peer(int my_id, int messages_count, size_t payload_size, int peers_c { /* Set myself as the persistent receiver of my mailbox so that messages start flowing to me as soon as they are put * into it */ - sg4::Mailbox* my_mbox = sg4::Mailbox::by_name(std::string("peer-") + std::to_string(my_id)); + sg4::Mailbox* my_mbox = sg4::Mailbox::by_name("peer-" + std::to_string(my_id)); my_mbox->set_receiver(sg4::Actor::self()); std::vector pending_comms; @@ -39,8 +39,8 @@ static void peer(int my_id, int messages_count, size_t payload_size, int peers_c for (int i = 0; i < messages_count; i++) { for (int peer_id = 0; peer_id < peers_count; peer_id++) { if (peer_id != my_id) { - sg4::Mailbox* mbox = sg4::Mailbox::by_name(std::string("peer-") + std::to_string(peer_id)); - std::string message = std::string("Message ") + std::to_string(i) + " from peer " + std::to_string(my_id); + sg4::Mailbox* mbox = sg4::Mailbox::by_name("peer-" + std::to_string(peer_id)); + std::string message = "Message " + std::to_string(i) + " from peer " + std::to_string(my_id); auto* payload = new std::string(message); // copy the data we send: // 'message' is not a stable storage location XBT_INFO("Send '%s' to '%s'", message.c_str(), mbox->get_cname()); @@ -53,7 +53,7 @@ static void peer(int my_id, int messages_count, size_t payload_size, int peers_c /* Start sending messages to let peers know that they should stop */ for (int peer_id = 0; peer_id < peers_count; peer_id++) { if (peer_id != my_id) { - sg4::Mailbox* mbox = sg4::Mailbox::by_name(std::string("peer-") + std::to_string(peer_id)); + sg4::Mailbox* mbox = sg4::Mailbox::by_name("peer-" + std::to_string(peer_id)); auto* payload = new std::string("finalize"); // Make a copy of the data we will send pending_comms.push_back(mbox->put_async(payload, payload_size)); XBT_INFO("Send 'finalize' to 'peer-%d'", peer_id); diff --git a/examples/cpp/comm-serialize/s4u-comm-serialize.cpp b/examples/cpp/comm-serialize/s4u-comm-serialize.cpp index 4c81a75aea..d7d25babda 100644 --- a/examples/cpp/comm-serialize/s4u-comm-serialize.cpp +++ b/examples/cpp/comm-serialize/s4u-comm-serialize.cpp @@ -39,7 +39,7 @@ public: /* Start dispatching all messages to receiver */ for (int i = 0; i < messages_count; i++) { - std::string msg_content = std::string("Message ") + std::to_string(i); + std::string msg_content = "Message " + std::to_string(i); // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets it auto* payload = new std::string(msg_content); diff --git a/examples/cpp/comm-testany/s4u-comm-testany.cpp b/examples/cpp/comm-testany/s4u-comm-testany.cpp index 3c673c8b19..a519a4a6f8 100644 --- a/examples/cpp/comm-testany/s4u-comm-testany.cpp +++ b/examples/cpp/comm-testany/s4u-comm-testany.cpp @@ -13,7 +13,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_testany, "Messages specific for this s4u e static void rank0() { - sg4::Mailbox* mbox = sg4::Mailbox::by_name(std::string("rank0")); + sg4::Mailbox* mbox = sg4::Mailbox::by_name("rank0"); std::string* msg1; std::string* msg2; std::string* msg3; @@ -26,7 +26,7 @@ static void rank0() XBT_INFO("Send some data to rank-1"); for (int i = 0; i < 3; i++) - sg4::Mailbox::by_name(std::string("rank1"))->put(new int(i), 1); + sg4::Mailbox::by_name("rank1")->put(new int(i), 1); XBT_INFO("Test for completed comms"); while (not pending_comms.empty()) { @@ -45,13 +45,13 @@ static void rank0() static void rank1() { - sg4::Mailbox* rank0_mbox = sg4::Mailbox::by_name(std::string("rank0")); - sg4::Mailbox* rank1_mbox = sg4::Mailbox::by_name(std::string("rank1")); + sg4::Mailbox* rank0_mbox = sg4::Mailbox::by_name("rank0"); + sg4::Mailbox* rank1_mbox = sg4::Mailbox::by_name("rank1"); for (int i = 0; i < 3; i++) { auto res = rank1_mbox->get_unique(); XBT_INFO("Received %d", *res); - std::string msg_content = std::string("Message ") + std::to_string(i); + std::string msg_content = "Message " + std::to_string(i); auto* payload = new std::string(msg_content); XBT_INFO("Send '%s'", msg_content.c_str()); rank0_mbox->put(payload, 1e6); diff --git a/examples/cpp/comm-wait/s4u-comm-wait.cpp b/examples/cpp/comm-wait/s4u-comm-wait.cpp index 74edc64152..6ec1b67516 100644 --- a/examples/cpp/comm-wait/s4u-comm-wait.cpp +++ b/examples/cpp/comm-wait/s4u-comm-wait.cpp @@ -30,7 +30,7 @@ static void sender(int messages_count, size_t payload_size) sg4::this_actor::sleep_for(sleep_start_time); for (int i = 0; i < messages_count; i++) { - std::string msg_content = std::string("Message ") + std::to_string(i); + std::string msg_content = "Message " + std::to_string(i); // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets the data auto* payload = new std::string(msg_content); diff --git a/examples/cpp/comm-waitall/s4u-comm-waitall.cpp b/examples/cpp/comm-waitall/s4u-comm-waitall.cpp index c0b347314c..19431a0d7d 100644 --- a/examples/cpp/comm-waitall/s4u-comm-waitall.cpp +++ b/examples/cpp/comm-waitall/s4u-comm-waitall.cpp @@ -33,12 +33,12 @@ static void sender(unsigned int messages_count, unsigned int receivers_count, lo /* Make a vector of the mailboxes to use */ std::vector mboxes; for (unsigned int i = 0; i < receivers_count; i++) - mboxes.push_back(sg4::Mailbox::by_name(std::string("receiver-") + std::to_string(i))); + mboxes.push_back(sg4::Mailbox::by_name("receiver-" + std::to_string(i))); // sphinx-doc: init-end /* Start dispatching all messages to receivers, in a round robin fashion */ for (unsigned int i = 0; i < messages_count; i++) { - std::string msg_content = std::string("Message ") + std::to_string(i); + std::string msg_content = "Message " + std::to_string(i); // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets it auto* payload = new std::string(msg_content); @@ -68,7 +68,7 @@ static void sender(unsigned int messages_count, unsigned int receivers_count, lo /* Receiver actor expects 1 argument: its ID */ static void receiver(int id) { - sg4::Mailbox* mbox = sg4::Mailbox::by_name(std::string("receiver-") + std::to_string(id)); + sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver-" + std::to_string(id)); XBT_INFO("Wait for my first message"); for (bool cont = true; cont;) { auto received = mbox->get_unique(); diff --git a/examples/cpp/comm-waitany/s4u-comm-waitany.cpp b/examples/cpp/comm-waitany/s4u-comm-waitany.cpp index 30cd1e7bc4..5d343fc2bd 100644 --- a/examples/cpp/comm-waitany/s4u-comm-waitany.cpp +++ b/examples/cpp/comm-waitany/s4u-comm-waitany.cpp @@ -37,11 +37,11 @@ static void sender(unsigned int messages_count, unsigned int receivers_count, lo /* Make a vector of the mailboxes to use */ std::vector mboxes; for (unsigned int i = 0; i < receivers_count; i++) - mboxes.push_back(sg4::Mailbox::by_name(std::string("receiver-") + std::to_string(i))); + mboxes.push_back(sg4::Mailbox::by_name("receiver-" + std::to_string(i))); /* Start dispatching all messages to receivers, in a round robin fashion */ for (unsigned int i = 0; i < messages_count; i++) { - std::string msg_content = std::string("Message ") + std::to_string(i); + std::string msg_content = "Message " + std::to_string(i); // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets it auto* payload = new std::string(msg_content); @@ -81,7 +81,7 @@ static void sender(unsigned int messages_count, unsigned int receivers_count, lo /* Receiver actor expects 1 argument: its ID */ static void receiver(int id) { - sg4::Mailbox* mbox = sg4::Mailbox::by_name(std::string("receiver-") + std::to_string(id)); + sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver-" + std::to_string(id)); XBT_INFO("Wait for my first message"); for (bool cont = true; cont;) { auto received = mbox->get_unique(); diff --git a/examples/cpp/comm-waituntil/s4u-comm-waituntil.cpp b/examples/cpp/comm-waituntil/s4u-comm-waituntil.cpp index a24ca3ab67..dc61966b53 100644 --- a/examples/cpp/comm-waituntil/s4u-comm-waituntil.cpp +++ b/examples/cpp/comm-waituntil/s4u-comm-waituntil.cpp @@ -25,7 +25,7 @@ static void sender(int messages_count, size_t payload_size) /* Start dispatching all messages to the receiver */ for (int i = 0; i < messages_count; i++) { - std::string message = std::string("Message ") + std::to_string(i); + std::string message = "Message " + std::to_string(i); auto* payload = new std::string(message); // copy the data we send: // 'msgName' is not a stable storage location diff --git a/examples/cpp/energy-link/s4u-energy-link.cpp b/examples/cpp/energy-link/s4u-energy-link.cpp index 66e849c337..d8030250e3 100644 --- a/examples/cpp/energy-link/s4u-energy-link.cpp +++ b/examples/cpp/energy-link/s4u-energy-link.cpp @@ -22,7 +22,7 @@ static void sender(std::vector args) long comm_size = std::stol(args.at(1)); XBT_INFO("Send %ld bytes, in %d flows", comm_size, flow_amount); - sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::string("message")); + sg4::Mailbox* mailbox = sg4::Mailbox::by_name("message"); /* Sleep a while before starting the example */ sg4::this_actor::sleep_for(10); @@ -47,7 +47,7 @@ static void receiver(std::vector args) XBT_INFO("Receiving %d flows ...", flow_amount); - sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::string("message")); + sg4::Mailbox* mailbox = sg4::Mailbox::by_name("message"); if (flow_amount == 1) { char* res = mailbox->get(); diff --git a/examples/cpp/exec-waitany/s4u-exec-waitany.cpp b/examples/cpp/exec-waitany/s4u-exec-waitany.cpp index 1a2b87d53b..ec5f495b48 100644 --- a/examples/cpp/exec-waitany/s4u-exec-waitany.cpp +++ b/examples/cpp/exec-waitany/s4u-exec-waitany.cpp @@ -17,7 +17,7 @@ static void worker(bool with_timeout) std::vector pending_executions; for (int i = 0; i < 3; i++) { - std::string name = std::string("Exec-") + std::to_string(i); + std::string name = "Exec-" + std::to_string(i); double amount = (6 * (i % 2) + i + 1) * sg4::this_actor::get_host()->get_speed(); sg4::ExecPtr exec = sg4::this_actor::exec_init(amount)->set_name(name); diff --git a/examples/cpp/network-factors/s4u-network-factors.cpp b/examples/cpp/network-factors/s4u-network-factors.cpp index abeeab7e64..70695f01d3 100644 --- a/examples/cpp/network-factors/s4u-network-factors.cpp +++ b/examples/cpp/network-factors/s4u-network-factors.cpp @@ -235,10 +235,9 @@ int main(int argc, char* argv[]) sg4::Host* host = e.host_by_name("dahu-1.grid5000.fr"); sg4::Host* host_remote = e.host_by_name("dahu-10.grid5000.fr"); - sg4::Actor::create(std::string("receiver-local"), host, Receiver()); - sg4::Actor::create(std::string("receiver-remote"), host_remote, Receiver()); - sg4::Actor::create(std::string("sender") + std::string(host->get_name()), host, - Sender({host, host_remote}, crosstraffic)); + sg4::Actor::create("receiver-local", host, Receiver()); + sg4::Actor::create("receiver-remote", host_remote, Receiver()); + sg4::Actor::create("sender" + host->get_name(), host, Sender({host, host_remote}, crosstraffic)); /* runs the simulation */ e.run(); diff --git a/examples/cpp/network-nonlinear/s4u-network-nonlinear.cpp b/examples/cpp/network-nonlinear/s4u-network-nonlinear.cpp index 292503e52b..b065a79be5 100644 --- a/examples/cpp/network-nonlinear/s4u-network-nonlinear.cpp +++ b/examples/cpp/network-nonlinear/s4u-network-nonlinear.cpp @@ -32,7 +32,7 @@ public: /* Start dispatching all messages to receiver */ for (int i = 0; i < messages_count; i++) { - std::string msg_content = std::string("Message ") + std::to_string(i); + std::string msg_content = "Message " + std::to_string(i); // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets it auto* payload = new std::string(msg_content); diff --git a/examples/cpp/platform-failures/s4u-platform-failures.cpp b/examples/cpp/platform-failures/s4u-platform-failures.cpp index c728cd3536..339b4742ff 100644 --- a/examples/cpp/platform-failures/s4u-platform-failures.cpp +++ b/examples/cpp/platform-failures/s4u-platform-failures.cpp @@ -38,7 +38,7 @@ static void master(std::vector args) XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, number_of_tasks); for (int i = 0; i < number_of_tasks; i++) { - mailbox = sg4::Mailbox::by_name(std::string("worker-") + std::to_string(i % workers_count)); + mailbox = sg4::Mailbox::by_name("worker-" + std::to_string(i % workers_count)); auto* payload = new double(comp_size); try { XBT_INFO("Send a message to %s", mailbox->get_cname()); @@ -56,7 +56,7 @@ static void master(std::vector args) XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over."); for (int i = 0; i < workers_count; i++) { /* - Eventually tell all the workers to stop by sending a "finalize" task */ - mailbox = sg4::Mailbox::by_name(std::string("worker-") + std::to_string(i)); + mailbox = sg4::Mailbox::by_name("worker-" + std::to_string(i)); auto* payload = new double(-1.0); try { mailbox->put(payload, 0, 1.0); @@ -76,7 +76,7 @@ static void worker(std::vector args) { xbt_assert(args.size() == 2, "Expecting one parameter"); long id = std::stol(args[1]); - sg4::Mailbox* mailbox = sg4::Mailbox::by_name(std::string("worker-") + std::to_string(id)); + sg4::Mailbox* mailbox = sg4::Mailbox::by_name("worker-" + std::to_string(id)); while (true) { try { XBT_INFO("Waiting a message on %s", mailbox->get_cname()); diff --git a/examples/cpp/platform-profile/s4u-platform-profile.cpp b/examples/cpp/platform-profile/s4u-platform-profile.cpp index 5e3602a8d1..7fad09b6d6 100644 --- a/examples/cpp/platform-profile/s4u-platform-profile.cpp +++ b/examples/cpp/platform-profile/s4u-platform-profile.cpp @@ -26,7 +26,7 @@ static void watcher() std::string path; for (const auto* l : links) - path += (path.empty() ? "" : ", ") + std::string("link '") + l->get_name() + std::string("'"); + path += std::string(path.empty() ? "" : ", ") + "link '" + l->get_name() + "'"; XBT_INFO("Path from Jupiter to Fafard: %s (latency: %fs).", path.c_str(), lat); for (int i = 0; i < 10; i++) { diff --git a/examples/cpp/plugin-prodcons/s4u-plugin-prodcons.cpp b/examples/cpp/plugin-prodcons/s4u-plugin-prodcons.cpp index 6ef625f8aa..f023e780bf 100644 --- a/examples/cpp/plugin-prodcons/s4u-plugin-prodcons.cpp +++ b/examples/cpp/plugin-prodcons/s4u-plugin-prodcons.cpp @@ -58,11 +58,11 @@ int main(int argc, char* argv[]) // Platform creation auto* cluster = sg4::create_star_zone("cluster"); for (int i = 0; i < 8; i++) { - std::string hostname = std::string("node-") + std::to_string(i) + ".simgrid.org"; + std::string hostname = "node-" + std::to_string(i) + ".simgrid.org"; const auto* host = cluster->create_host(hostname, "1Gf"); - std::string linkname = std::string("cluster") + "_link_" + std::to_string(i); + std::string linkname = "cluster_link_" + std::to_string(i); const auto* link = cluster->create_split_duplex_link(linkname, "1Gbps"); cluster->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, {{link, sg4::LinkInRoute::Direction::UP}}, @@ -78,10 +78,10 @@ int main(int argc, char* argv[]) XBT_INFO("Transfers are done in %s mode", pc->get_transfer_mode().c_str()); for (int i = 0; i < 3; i++) { - std::string hostname = std::string("node-") + std::to_string(i) + ".simgrid.org"; + std::string hostname = "node-" + std::to_string(i) + ".simgrid.org"; sg4::Actor::create("ingester-" + std::to_string(i), e.host_by_name(hostname), &ingester, i, pc); - hostname = std::string("node-") + std::to_string(i + 3) + ".simgrid.org"; + hostname = "node-" + std::to_string(i + 3) + ".simgrid.org"; sg4::Actor::create("retriever-" + std::to_string(i), e.host_by_name(hostname), &retriever, pc); } diff --git a/examples/cpp/replay-comm/s4u-replay-comm.cpp b/examples/cpp/replay-comm/s4u-replay-comm.cpp index e53af5bb3b..f4052a1086 100644 --- a/examples/cpp/replay-comm/s4u-replay-comm.cpp +++ b/examples/cpp/replay-comm/s4u-replay-comm.cpp @@ -71,7 +71,7 @@ public: static void recv(simgrid::xbt::ReplayAction& action) { double clock = sg4::Engine::get_clock(); - sg4::Mailbox* from = sg4::Mailbox::by_name(std::string(action[2]) + "_" + sg4::this_actor::get_name()); + sg4::Mailbox* from = sg4::Mailbox::by_name(action[2] + "_" + sg4::this_actor::get_name()); ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME.c_str(), sg4::this_actor::get_cname(), from->get_cname()); from->get_unique(); diff --git a/examples/cpp/synchro-condition-variable/s4u-synchro-condition-variable.cpp b/examples/cpp/synchro-condition-variable/s4u-synchro-condition-variable.cpp index 3602e1dd3c..07edf8a61a 100644 --- a/examples/cpp/synchro-condition-variable/s4u-synchro-condition-variable.cpp +++ b/examples/cpp/synchro-condition-variable/s4u-synchro-condition-variable.cpp @@ -17,7 +17,7 @@ static void worker_fun(sg4::ConditionVariablePtr cv, sg4::MutexPtr mutex) std::unique_lock lock(*mutex); XBT_INFO("Start processing data which is '%s'.", data.c_str()); - data += std::string(" after processing"); + data += " after processing"; // Send data back to main() XBT_INFO("Signal to master that the data processing is completed, and exit."); @@ -30,7 +30,7 @@ static void master_fun() { auto mutex = sg4::Mutex::create(); auto cv = sg4::ConditionVariable::create(); - data = std::string("Example data"); + data = "Example data"; auto worker = sg4::Actor::create("worker", sg4::Host::by_name("Jupiter"), worker_fun, cv, mutex); // wait for the worker diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index 342bd4bb2e..d09e6a8208 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -183,9 +183,7 @@ class XBT_PUBLIC ForcefulKillException { */ public: ForcefulKillException() = default; - explicit ForcefulKillException(const std::string& msg) : msg_(std::string("Actor killed (") + msg + std::string(").")) - { - } + explicit ForcefulKillException(const std::string& msg) : msg_("Actor killed (" + msg + ").") {} ~ForcefulKillException(); const char* what() const noexcept { return msg_.c_str(); } @@ -193,7 +191,7 @@ public: static bool try_n_catch(const std::function& try_block); private: - std::string msg_ = std::string("Actor killed."); + std::string msg_ = "Actor killed."; }; } // namespace simgrid diff --git a/include/simgrid/instr.h b/include/simgrid/instr.h index cff543619a..df7036c407 100644 --- a/include/simgrid/instr.h +++ b/include/simgrid/instr.h @@ -17,7 +17,7 @@ namespace simgrid { namespace instr { /* User-variables related functions*/ /* for host variables */ -XBT_PUBLIC void declare_host_variable(const std::string& variable, const std::string& color = std::string("")); +XBT_PUBLIC void declare_host_variable(const std::string& variable, const std::string& color = ""); XBT_PUBLIC void set_host_variable(const std::string& host, const std::string& variable, double value, double time = simgrid_get_clock()); XBT_PUBLIC void add_host_variable(const std::string& host, const std::string& variable, double value, @@ -27,7 +27,7 @@ XBT_PUBLIC void sub_host_variable(const std::string& host, const std::string& va XBT_PUBLIC const std::set>& get_host_variables(); /* for link variables */ -XBT_PUBLIC void declare_link_variable(const std::string& variable, const std::string& color = std::string("")); +XBT_PUBLIC void declare_link_variable(const std::string& variable, const std::string& color = ""); XBT_PUBLIC void set_link_variable(const std::string& link, const std::string& variable, double value, double time = simgrid_get_clock()); XBT_PUBLIC void add_link_variable(const std::string& link, const std::string& variable, double value, @@ -44,7 +44,7 @@ XBT_PUBLIC void sub_link_variable(const std::string& src, const std::string& dst XBT_PUBLIC const std::set>& get_link_variables(); /* for VM variables */ -XBT_PUBLIC void declare_vm_variable(const std::string& variable, const std::string& color = std::string("")); +XBT_PUBLIC void declare_vm_variable(const std::string& variable, const std::string& color = ""); XBT_PUBLIC void set_vm_variable(const std::string& vm, const std::string& variable, double value, double time = simgrid_get_clock()); XBT_PUBLIC void add_vm_variable(const std::string& vm, const std::string& variable, double value, @@ -56,7 +56,7 @@ XBT_PUBLIC const std::set>& get_vm_variables(); /* Functions to manage tracing marks (used for trace comparison experiments) */ XBT_PUBLIC void declare_mark(const std::string& mark_type); XBT_PUBLIC void declare_mark_value(const std::string& mark_type, const std::string& mark_value, - const std::string& mark_color = std::string("1 1 1")); + const std::string& mark_color = "1 1 1"); XBT_PUBLIC void mark(const std::string& mark_type, const std::string& mark_value); XBT_PUBLIC const std::set>& get_marks(); diff --git a/include/simgrid/plugins/ProducerConsumer.hpp b/include/simgrid/plugins/ProducerConsumer.hpp index 6f4f909aef..45f7cd0348 100644 --- a/include/simgrid/plugins/ProducerConsumer.hpp +++ b/include/simgrid/plugins/ProducerConsumer.hpp @@ -75,7 +75,7 @@ private: { xbt_assert(max_queue_size > 0, "Max queue size of 0 is not allowed"); - id = std::string("ProducerConsumer") + std::to_string(pc_id); + id = "ProducerConsumer" + std::to_string(pc_id); pc_id++; mutex_ = s4u::Mutex::create(); diff --git a/include/xbt/config.hpp b/include/xbt/config.hpp index 397870e61c..a02a076986 100644 --- a/include/xbt/config.hpp +++ b/include/xbt/config.hpp @@ -174,7 +174,7 @@ bind_flag(std::string& value, const char* name, const char* description, if (val == "help") mesg += std::string("Possible values for option ") + name + ":\n"; else - mesg += std::string("Invalid value '") + val + "' for option " + name + ". Possible values:\n"; + mesg += "Invalid value '" + val + "' for option " + name + ". Possible values:\n"; for (auto const& kv : valid_values) mesg += " - '" + kv.first + "': " + kv.second + (kv.first == value ? " <=== DEFAULT" : "") + "\n"; xbt_die("%s", mesg.c_str()); diff --git a/src/bindings/java/jmsg_comm.cpp b/src/bindings/java/jmsg_comm.cpp index 0eaa12d63f..ce0d030eee 100644 --- a/src/bindings/java/jmsg_comm.cpp +++ b/src/bindings/java/jmsg_comm.cpp @@ -128,7 +128,7 @@ static msg_comm_t* jarray_to_commArray(JNIEnv *env, jobjectArray jcomms, /* OUT comms[i] = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind); if (not comms[i]) { - jxbt_throw_null(env, std::string("comm at rank ") + std::to_string(i) + " is null"); + jxbt_throw_null(env, "comm at rank " + std::to_string(i) + " is null"); return nullptr; } diff --git a/src/bindings/java/jmsg_process.cpp b/src/bindings/java/jmsg_process.cpp index ffbf7ff7c8..a561d17700 100644 --- a/src/bindings/java/jmsg_process.cpp +++ b/src/bindings/java/jmsg_process.cpp @@ -114,7 +114,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jcl auto const* actor = sg_actor_by_pid(pid); if (not actor) { - jxbt_throw_process_not_found(env, std::string("PID = ") + std::to_string(static_cast(pid))); + jxbt_throw_process_not_found(env, "PID = " + std::to_string(static_cast(pid))); return nullptr; } diff --git a/src/bindings/java/jxbt_utilities.hpp b/src/bindings/java/jxbt_utilities.hpp index 63988babbf..919ac6ec88 100644 --- a/src/bindings/java/jxbt_utilities.hpp +++ b/src/bindings/java/jxbt_utilities.hpp @@ -84,7 +84,7 @@ public: env_->ReleaseStringUTFChars(jstr_, value); } operator const char*() const { return value; } - operator const std::string() const { return std::string(value); } + operator const std::string() const { return value; } }; #endif diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp index 8aad6d59f3..51b42fb299 100644 --- a/src/bindings/python/simgrid_python.cpp +++ b/src/bindings/python/simgrid_python.cpp @@ -641,7 +641,7 @@ PYBIND11_MODULE(simgrid, m) py::class_>( m, "Mailbox", "Mailbox. See the C++ documentation for details.") .def( - "__str__", [](const Mailbox* self) { return std::string("Mailbox(") + self->get_cname() + ")"; }, + "__str__", [](const Mailbox* self) { return "Mailbox(" + self->get_name() + ")"; }, "Textual representation of the Mailbox`") .def_static("by_name", &Mailbox::by_name, py::call_guard(), py::arg("name"), "Retrieve a Mailbox from its name") @@ -716,7 +716,7 @@ PYBIND11_MODULE(simgrid, m) "Retrieve the mailbox on which this comm acts.") .def_property_readonly("sender", &Comm::get_sender, py::call_guard()) - .def_property_readonly("state_str", [](const Comm* self){ return std::string(self->get_state_str()); }, + .def_property_readonly("state_str", &Comm::get_state_str, py::call_guard(), "Retrieve the Comm state as string") .def_property_readonly("remaining", &Comm::get_remaining, diff --git a/src/dag/loaders.cpp b/src/dag/loaders.cpp index c6d288db6b..bba69d8f38 100644 --- a/src/dag/loaders.cpp +++ b/src/dag/loaders.cpp @@ -295,7 +295,7 @@ std::vector create_DAG_from_dot(const std::string& filename) void STag_dax__adag() { try { - double version = std::stod(std::string(A_dax__adag_version)); + double version = std::stod(A_dax__adag_version); xbt_assert(version == 2.1, "Expected version 2.1 in tag, got %f. Fix the parser or your file", version); } catch (const std::invalid_argument&) { throw std::invalid_argument(std::string("Parse error: ") + A_dax__adag_version + " is not a double"); @@ -305,7 +305,7 @@ void STag_dax__adag() void STag_dax__job() { try { - double runtime = std::stod(std::string(A_dax__job_runtime)); + double runtime = std::stod(A_dax__job_runtime); std::string name = std::string(A_dax__job_id) + "@" + A_dax__job_name; runtime *= 4200000000.; /* Assume that timings were done on a 4.2GFlops machine. I mean, why not? */ @@ -322,7 +322,7 @@ void STag_dax__uses() { double size; try { - size = std::stod(std::string(A_dax__uses_size)); + size = std::stod(A_dax__uses_size); } catch (const std::invalid_argument&) { throw std::invalid_argument(std::string("Parse error: ") + A_dax__uses_size + " is not a double"); } @@ -357,7 +357,7 @@ void STag_dax__child() if (job != simgrid::s4u::jobs.end()) { current_child = job->second; } else { - throw std::out_of_range(std::string("Parse error on line ") + std::to_string(dax_lineno) + + throw std::out_of_range("Parse error on line " + std::to_string(dax_lineno) + ": Asked to add dependencies to the non-existent " + A_dax__child_ref + "task"); } } @@ -375,9 +375,9 @@ void STag_dax__parent() parent->add_successor(current_child); XBT_DEBUG("Control-flow dependency from %s to %s", current_child->get_cname(), parent->get_cname()); } else { - throw std::out_of_range(std::string("Parse error on line ") + std::to_string(dax_lineno) + - ": Asked to add a dependency from " + current_child->get_name() + " to " + - A_dax__parent_ref + ", but " + A_dax__parent_ref + " does not exist"); + throw std::out_of_range("Parse error on line " + std::to_string(dax_lineno) + ": Asked to add a dependency from " + + current_child->get_name() + " to " + A_dax__parent_ref + ", but " + A_dax__parent_ref + + " does not exist"); } } diff --git a/src/instr/instr_interface.cpp b/src/instr/instr_interface.cpp index 73de1d2b71..85bf39e0a0 100644 --- a/src/instr/instr_interface.cpp +++ b/src/instr/instr_interface.cpp @@ -312,7 +312,7 @@ void declare_tracing_category(const std::string& name, const std::string& color) double blue = simgrid::xbt::random::uniform_real(0.0, std::nextafter(1.0, 2.0)); final_color = std::to_string(red) + " " + std::to_string(green) + " " + std::to_string(blue); } else { - final_color = std::string(color); + final_color = color; } XBT_DEBUG("CAT,declare %s, \"%s\" \"%s\"", name.c_str(), color.c_str(), final_color.c_str()); diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index f53a60866c..5001fc73b8 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -20,7 +20,7 @@ NetZoneContainer::NetZoneContainer(const std::string& name, unsigned int level, { xbt_assert(s4u::Engine::get_instance()->netpoint_by_name_or_null(get_name()), "Element '%s' not found", get_cname()); if (parent_) { - std::string type_name = std::string("L") + std::to_string(level); + std::string type_name = "L" + std::to_string(level); type_ = parent_->type_->by_name_or_create(type_name); parent_->children_.try_emplace(get_name(), this); on_creation(*this); diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index d5658efb7d..9d7100eb6a 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -68,7 +68,7 @@ void VariableType::instr_event(double now, double delta, const char* resource, d // create a key considering the resource and variable, and check if key exists in the global map: // if it doesn't, set the variable to zero. if (static std::set> platform_variables; - platform_variables.emplace(std::string(resource) + get_name()).second) + platform_variables.emplace(resource + get_name()).second) set_event(now, 0); add_event(now, value); diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index b37ed60a7f..5a5ad7a12e 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -24,7 +24,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_routing, instr, "Tracing platform hierarch std::string instr_pid(simgrid::s4u::Actor const& proc) { - return std::string(proc.get_name()) + "-" + std::to_string(proc.get_pid()); + return proc.get_name() + "-" + std::to_string(proc.get_pid()); } static simgrid::instr::Container* lowestCommonAncestor(const simgrid::instr::Container* a1, @@ -142,10 +142,10 @@ static void recursiveNewVariableType(const std::string& new_typename, const std: simgrid::instr::Type* root) { if (root->get_name() == "HOST" || root->get_name() == "VM") - root->by_name_or_create(std::string("p") + new_typename, color); + root->by_name_or_create("p" + new_typename, color); if (root->get_name() == "LINK") - root->by_name_or_create(std::string("b") + new_typename, color); + root->by_name_or_create("b" + new_typename, color); for (auto const& [_, child] : root->get_children()) { recursiveNewVariableType(new_typename, color, child.get()); @@ -501,14 +501,12 @@ void define_callbacks() if (TRACE_smpi_is_enabled() && TRACE_smpi_is_computing()) { s4u::Exec::on_start_cb([](s4u::Exec const& exec) { - Container::by_name(std::string("rank-") + std::to_string(s4u::Actor::self()->get_pid())) + Container::by_name("rank-" + std::to_string(s4u::Actor::self()->get_pid())) ->get_state("MPI_STATE") ->push_event("computing", new CpuTIData("compute", exec.get_cost())); }); s4u::Activity::on_completion_cb([](const s4u::Activity&) { - Container::by_name(std::string("rank-") + std::to_string(s4u::Actor::self()->get_pid())) - ->get_state("MPI_STATE") - ->pop_event(); + Container::by_name("rank-" + std::to_string(s4u::Actor::self()->get_pid()))->get_state("MPI_STATE")->pop_event(); }); } diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 4a41dd014e..cd8980017d 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -68,7 +68,7 @@ static inline std::string contexts_list() } static config::Flag context_factory_name("contexts/factory", - (std::string("Possible values: ") + contexts_list()).c_str(), + ("Possible values: " + contexts_list()).c_str(), context_factories.begin()->first); } // namespace simgrid::kernel diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index 6def798184..be71dd3dee 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -66,7 +66,7 @@ ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* h throw HostFailureException(XBT_THROW_POINT, "Cannot attach actor on failed host."); } - auto* actor = new ActorImpl(std::string(name), host, /*ppid*/ -1); + auto* actor = new ActorImpl(name, host, /*ppid*/ -1); /* Actor data */ actor->piface_.set_data(data); actor->code_ = nullptr; @@ -371,8 +371,8 @@ activity::ActivityImplPtr ActorImpl::join(const ActorImpl* actor, double timeout activity::ActivityImplPtr ActorImpl::sleep(double duration) { if (not host_->is_on()) - throw_exception(std::make_exception_ptr(HostFailureException( - XBT_THROW_POINT, std::string("Host ") + host_->get_cname() + " failed, you cannot sleep there."))); + throw_exception(std::make_exception_ptr( + HostFailureException(XBT_THROW_POINT, "Host " + host_->get_name() + " failed, you cannot sleep there."))); auto sleep_activity = new activity::SleepImpl(); sleep_activity->set_name("sleep").set_host(host_).set_duration(duration).start(); diff --git a/src/kernel/actor/CommObserver.cpp b/src/kernel/actor/CommObserver.cpp index ae1d392b07..1ea0494a58 100644 --- a/src/kernel/actor/CommObserver.cpp +++ b/src/kernel/actor/CommObserver.cpp @@ -56,7 +56,7 @@ static std::string to_string_activity_test(const activity::ActivityImpl* act) if (auto* comm = dynamic_cast(act)) { const std::string src_buff_id = ptr_to_id(comm->src_buff_); const std::string dst_buff_id = ptr_to_id(comm->dst_buff_); - return std::string("CommTest(comm_id:") + ptr_to_id(comm) + + return "CommTest(comm_id:" + ptr_to_id(comm) + " src:" + std::to_string(comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1) + " dst:" + std::to_string(comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1) + " mbox:" + std::to_string(comm->get_mailbox_id()) + " srcbuf:" + src_buff_id + " dstbuf:" + dst_buff_id + @@ -109,10 +109,10 @@ static std::string to_string_activity_wait(const activity::ActivityImpl* act) if (auto* comm = dynamic_cast(act)) { const std::string src_buff_id = ptr_to_id(comm->src_buff_); const std::string dst_buff_id = ptr_to_id(comm->dst_buff_); - return std::string("CommWait(comm_id:") + ptr_to_id(comm) + + return "CommWait(comm_id:" + ptr_to_id(comm) + " src:" + std::to_string(comm->src_actor_ != nullptr ? comm->src_actor_->get_pid() : -1) + " dst:" + std::to_string(comm->dst_actor_ != nullptr ? comm->dst_actor_->get_pid() : -1) + - " mbox:" + std::string(comm->get_mailbox() == nullptr ? std::string("-") : comm->get_mailbox()->get_name()) + + " mbox:" + (comm->get_mailbox() == nullptr ? "-" : comm->get_mailbox()->get_name()) + "(id:" + std::to_string(comm->get_mailbox_id()) + ") srcbuf:" + src_buff_id + " dstbuf:" + dst_buff_id + " bufsize:" + std::to_string(comm->src_buff_size_) + ")"; } else { @@ -205,9 +205,9 @@ void CommIsendSimcall::serialize(std::stringstream& stream) const } std::string CommIsendSimcall::to_string() const { - return std::string("CommAsyncSend(comm_id: ") + std::to_string((uintptr_t)comm_) + - " mbox:" + std::to_string(mbox_->get_id()) + " srcbuf:" + ptr_to_id(src_buff_) + - " bufsize:" + std::to_string(src_buff_size_) + " tag: " + std::to_string(tag_) + ")"; + return "CommAsyncSend(comm_id: " + std::to_string((uintptr_t)comm_) + " mbox:" + std::to_string(mbox_->get_id()) + + " srcbuf:" + ptr_to_id(src_buff_) + " bufsize:" + std::to_string(src_buff_size_) + + " tag: " + std::to_string(tag_) + ")"; } void CommIrecvSimcall::serialize(std::stringstream& stream) const @@ -218,7 +218,7 @@ void CommIrecvSimcall::serialize(std::stringstream& stream) const } std::string CommIrecvSimcall::to_string() const { - return std::string("CommAsyncRecv(comm_id: ") + ptr_to_id(comm_) + + return "CommAsyncRecv(comm_id: " + ptr_to_id(comm_) + " mbox:" + std::to_string(mbox_->get_id()) + " dstbuf:" + ptr_to_id(dst_buff_) + " tag: " + std::to_string(tag_) + ")"; } diff --git a/src/kernel/actor/SimcallObserver.cpp b/src/kernel/actor/SimcallObserver.cpp index 0246d5a324..162653dcc6 100644 --- a/src/kernel/actor/SimcallObserver.cpp +++ b/src/kernel/actor/SimcallObserver.cpp @@ -23,7 +23,7 @@ void RandomSimcall::serialize(std::stringstream& stream) const } std::string RandomSimcall::to_string() const { - return std::string("Random(min:") + std::to_string(min_) + " max:" + std::to_string(max_) + ")"; + return "Random(min:" + std::to_string(min_) + " max:" + std::to_string(max_) + ")"; } void RandomSimcall::prepare(int times_considered) @@ -69,7 +69,7 @@ void ActorJoinSimcall::serialize(std::stringstream& stream) const } std::string ActorJoinSimcall::to_string() const { - return std::string("ActorJoin(pid:") + std::to_string(other_->get_pid()) + ")"; + return "ActorJoin(pid:" + std::to_string(other_->get_pid()) + ")"; } void ObjectAccessSimcallObserver::serialize(std::stringstream& stream) const @@ -79,7 +79,7 @@ void ObjectAccessSimcallObserver::serialize(std::stringstream& stream) const } std::string ObjectAccessSimcallObserver::to_string() const { - return std::string("ObjectAccess(obj:") + ptr_to_id(object_) + + return "ObjectAccess(obj:" + ptr_to_id(object_) + " owner:" + std::to_string(get_owner()->get_pid()) + ")"; } bool ObjectAccessSimcallObserver::is_visible() const diff --git a/src/kernel/resource/FactorSet.cpp b/src/kernel/resource/FactorSet.cpp index 47a129d43b..d1ecb610aa 100644 --- a/src/kernel/resource/FactorSet.cpp +++ b/src/kernel/resource/FactorSet.cpp @@ -57,14 +57,14 @@ void FactorSet::parse(const std::string& values) try { fact.factor = std::stoi(*factor_iter); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid factor in chunk ") + std::to_string(factors_.size() + 1) + - ": " + *factor_iter + " for " + name_); + throw std::invalid_argument("Invalid factor in chunk " + std::to_string(factors_.size() + 1) + ": " + + *factor_iter + " for " + name_); } } else { try { fact.values.push_back(xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, *factor_iter, "")); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid factor value ") + std::to_string(iteration) + " in chunk " + + throw std::invalid_argument("Invalid factor value " + std::to_string(iteration) + " in chunk " + std::to_string(factors_.size() + 1) + ": " + *factor_iter + " for " + name_); } } diff --git a/src/kernel/routing/DragonflyZone.cpp b/src/kernel/routing/DragonflyZone.cpp index e1370f33ac..9254c5617a 100644 --- a/src/kernel/routing/DragonflyZone.cpp +++ b/src/kernel/routing/DragonflyZone.cpp @@ -73,14 +73,14 @@ s4u::DragonflyParams DragonflyZone::parse_topo_parameters(const std::string& top try { n_groups = std::stoi(tmp[0]); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid number of groups:") + tmp[0]); + throw std::invalid_argument("Invalid number of groups:" + tmp[0]); } unsigned int n_blue; try { n_blue = std::stoi(tmp[1]); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid number of links for the blue level:") + tmp[1]); + throw std::invalid_argument("Invalid number of links for the blue level:" + tmp[1]); } // Black network : number of chassis/group, number of links between each router on the black network @@ -92,14 +92,14 @@ s4u::DragonflyParams DragonflyZone::parse_topo_parameters(const std::string& top try { n_chassis = std::stoi(tmp[0]); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid number of chassis:") + tmp[0]); + throw std::invalid_argument("Invalid number of chassis:" + tmp[0]); } unsigned int n_black; try { n_black = std::stoi(tmp[1]); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid number of links for the black level:") + tmp[1]); + throw std::invalid_argument("Invalid number of links for the black level:" + tmp[1]); } // Green network : number of blades/chassis, number of links between each router on the green network @@ -111,14 +111,14 @@ s4u::DragonflyParams DragonflyZone::parse_topo_parameters(const std::string& top try { n_routers = std::stoi(tmp[0]); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid number of routers:") + tmp[0]); + throw std::invalid_argument("Invalid number of routers:" + tmp[0]); } unsigned int n_green; try { n_green = std::stoi(tmp[1]); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid number of links for the green level:") + tmp[1]); + throw std::invalid_argument("Invalid number of links for the green level:" + tmp[1]); } // The last part of topo_parameters should be the number of nodes per blade @@ -126,7 +126,7 @@ s4u::DragonflyParams DragonflyZone::parse_topo_parameters(const std::string& top try { n_nodes = std::stoi(parameters[3]); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Last parameter is not the amount of nodes per blade:") + parameters[3]); + throw std::invalid_argument("Last parameter is not the amount of nodes per blade:" + parameters[3]); } return s4u::DragonflyParams({n_groups, n_blue}, {n_chassis, n_black}, {n_routers, n_green}, n_nodes); } diff --git a/src/kernel/routing/FatTreeZone.cpp b/src/kernel/routing/FatTreeZone.cpp index 3c6bfc62c9..73e8ec7c5c 100644 --- a/src/kernel/routing/FatTreeZone.cpp +++ b/src/kernel/routing/FatTreeZone.cpp @@ -232,9 +232,9 @@ void FatTreeZone::generate_switches(const s4u::ClusterCallbacks& set_callbacks) this->nodes_by_level_[0] *= this->num_children_per_node_[i]; if (this->nodes_by_level_[0] != this->nodes_.size()) { - surf_parse_error(std::string("The number of provided nodes does not fit with the wanted topology.") + - " Please check your platform description (We need " + std::to_string(this->nodes_by_level_[0]) + - "nodes, we got " + std::to_string(this->nodes_.size())); + surf_parse_error("The number of provided nodes does not fit with the wanted topology." + " Please check your platform description (We need " + + std::to_string(this->nodes_by_level_[0]) + "nodes, we got " + std::to_string(this->nodes_.size())); } for (unsigned int i = 0; i < this->levels_; i++) { @@ -423,12 +423,12 @@ s4u::FatTreeParams FatTreeZone::parse_topo_parameters(const std::string& topo_pa try { n_lev = std::stoi(parameters[0]); } catch (const std::invalid_argument&) { - surf_parse_error(std::string("First parameter is not the amount of levels: ") + parameters[0]); + surf_parse_error("First parameter is not the amount of levels: " + parameters[0]); } // Then, a l-sized vector standing for the children number by level boost::split(tmp, parameters[1], boost::is_any_of(",")); - surf_parse_assert(tmp.size() == n_lev, std::string("You specified ") + std::to_string(n_lev) + + surf_parse_assert(tmp.size() == n_lev, "You specified " + std::to_string(n_lev) + " levels but the child count vector (the first one) contains " + std::to_string(tmp.size()) + " levels."); @@ -436,33 +436,33 @@ s4u::FatTreeParams FatTreeZone::parse_topo_parameters(const std::string& topo_pa try { down.push_back(std::stoi(level)); } catch (const std::invalid_argument&) { - surf_parse_error(std::string("Invalid child count: ") + level); + surf_parse_error("Invalid child count: " + level); } } // Then, a l-sized vector standing for the parents number by level boost::split(tmp, parameters[2], boost::is_any_of(",")); - surf_parse_assert(tmp.size() == n_lev, std::string("You specified ") + std::to_string(n_lev) + + surf_parse_assert(tmp.size() == n_lev, "You specified " + std::to_string(n_lev) + " levels but the parent count vector (the second one) contains " + std::to_string(tmp.size()) + " levels."); for (std::string const& parent : tmp) { try { up.push_back(std::stoi(parent)); } catch (const std::invalid_argument&) { - surf_parse_error(std::string("Invalid parent count: ") + parent); + surf_parse_error("Invalid parent count: " + parent); } } // Finally, a l-sized vector standing for the ports number with the lower level boost::split(tmp, parameters[3], boost::is_any_of(",")); - surf_parse_assert(tmp.size() == n_lev, std::string("You specified ") + std::to_string(n_lev) + + surf_parse_assert(tmp.size() == n_lev, "You specified " + std::to_string(n_lev) + " levels but the port count vector (the third one) contains " + std::to_string(tmp.size()) + " levels."); for (std::string const& port : tmp) { try { count.push_back(std::stoi(port)); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid lower level port number:") + port); + throw std::invalid_argument("Invalid lower level port number:" + port); } } return s4u::FatTreeParams(n_lev, down, up, count); diff --git a/src/mc/ModelChecker.hpp b/src/mc/ModelChecker.hpp index 787bd04d1b..504f6826cf 100644 --- a/src/mc/ModelChecker.hpp +++ b/src/mc/ModelChecker.hpp @@ -40,10 +40,7 @@ public: Channel& channel() { return checker_side_.get_channel(); } PageStore& page_store() { return page_store_; } - std::string const& get_host_name(const char* hostname) - { - return *this->hostnames_.insert(std::string(hostname)).first; - } + std::string const& get_host_name(const char* hostname) { return *this->hostnames_.insert(hostname).first; } void start(); void shutdown(); diff --git a/src/mc/inspect/mc_dwarf.cpp b/src/mc/inspect/mc_dwarf.cpp index 44ad73ee0d..7b0c0f5089 100644 --- a/src/mc/inspect/mc_dwarf.cpp +++ b/src/mc/inspect/mc_dwarf.cpp @@ -510,7 +510,7 @@ static simgrid::mc::Type MC_dwarf_die_to_type(simgrid::mc::ObjectInformation* in { simgrid::mc::Type type; type.type = dwarf_tag(die); - type.name = std::string(); + type.name = ""; type.element_count = -1; // Global Offset @@ -677,7 +677,7 @@ static std::unique_ptr MC_die_to_variable(simgrid::mc::Ob } if (ns && variable->global) - variable->name = std::string(ns) + "::" + variable->name; + variable->name.insert(0, std::string(ns) + "::"); // The current code needs a variable name, // generate a fake one: diff --git a/src/mc/remote/RemoteProcess.cpp b/src/mc/remote/RemoteProcess.cpp index 75a610d44d..121341aab0 100644 --- a/src/mc/remote/RemoteProcess.cpp +++ b/src/mc/remote/RemoteProcess.cpp @@ -317,7 +317,7 @@ std::string RemoteProcess::read_string(RemotePtr address) const xbt_assert(c > 0, "Could not read string from remote process"); if (memchr(res.data() + off, '\0', c)) - return std::string(res.data()); + return res.data(); off += c; if (off == (off_t)res.size()) diff --git a/src/mc/sosp/Snapshot.cpp b/src/mc/sosp/Snapshot.cpp index b36d8cd89f..01ae368866 100644 --- a/src/mc/sosp/Snapshot.cpp +++ b/src/mc/sosp/Snapshot.cpp @@ -130,7 +130,7 @@ static std::vector unwind_stack_frames(UnwindContext* stack_ stack_frame.frame_base = (unw_word_t)frame->frame_base(c); } else { stack_frame.frame_base = 0; - stack_frame.frame_name = std::string(); + stack_frame.frame_name = ""; } result.push_back(std::move(stack_frame)); diff --git a/src/msg/msg_private.hpp b/src/msg/msg_private.hpp index 2579f3b793..c2bf802123 100644 --- a/src/msg/msg_private.hpp +++ b/src/msg/msg_private.hpp @@ -57,7 +57,7 @@ public: void set_not_used() { this->is_used_ = false; } const std::string& get_name() const { return name_; } const char* get_cname() const { return name_.c_str(); } - void set_name(const char* new_name) { name_ = std::string(new_name); } + void set_name(const char* new_name) { name_ = new_name; } void set_tracing_category(const char* category) { tracing_category_ = category ? category : ""; } const std::string& get_tracing_category() const { return tracing_category_; } bool has_tracing_category() { return not tracing_category_.empty(); } diff --git a/src/msg/msg_task.cpp b/src/msg/msg_task.cpp index 146845c5cf..122b506d07 100644 --- a/src/msg/msg_task.cpp +++ b/src/msg/msg_task.cpp @@ -103,7 +103,7 @@ s4u::CommPtr Task::send_async(const std::string& alias, void_f_pvoid_t cleanup, { if (TRACE_actor_is_enabled()) { auto* process_container = instr::Container::by_name(instr_pid(*MSG_process_self())); - std::string key = std::string("p") + std::to_string(get_id()); + std::string key = "p" + std::to_string(get_id()); instr::Container::get_root()->get_link("ACTOR_LINK")->start_event(process_container, "SR", key); } @@ -574,7 +574,7 @@ msg_error_t MSG_task_receive_with_timeout_bounded(msg_task_t* task, const char* if (TRACE_actor_is_enabled() && ret != MSG_HOST_FAILURE && ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) { auto* process_container = simgrid::instr::Container::by_name(instr_pid(*MSG_process_self())); - std::string key = std::string("p") + std::to_string((*task)->get_id()); + std::string key = "p" + std::to_string((*task)->get_id()); simgrid::instr::Container::get_root()->get_link("ACTOR_LINK")->end_event(process_container, "SR", key); } return ret; diff --git a/src/plugins/file_system/s4u_FileSystem.cpp b/src/plugins/file_system/s4u_FileSystem.cpp index 1a7ccccfbd..31f743a4f5 100644 --- a/src/plugins/file_system/s4u_FileSystem.cpp +++ b/src/plugins/file_system/s4u_FileSystem.cpp @@ -58,7 +58,7 @@ const Disk* File::find_local_disk_on(const Host* host) host->get_cname()); /* Mount point found, split fullpath_ into mount_name and path+filename*/ mount_point_ = fullpath_.substr(0, longest_prefix_length); - if (mount_point_ == std::string("/")) + if (mount_point_ == "/") path_ = fullpath_; else path_ = fullpath_.substr(longest_prefix_length, fullpath_.length()); @@ -307,7 +307,7 @@ int File::remote_copy(sg_host_t host, const std::string& fullpath) for (auto const& disk : host->get_disks()) { std::string current_mount = disk->extension()->get_mount_point(); - std::string mount_point = std::string(fullpath).substr(0, current_mount.length()); + std::string mount_point = fullpath.substr(0, current_mount.length()); if (mount_point == current_mount && current_mount.length() > longest_prefix_length) { /* The current mount name is found in the full path and is bigger than the previous*/ longest_prefix_length = current_mount.length(); @@ -348,9 +348,9 @@ FileSystemDiskExt::FileSystemDiskExt(const Disk* ptr) } if (const char* current_mount_str = ptr->get_property("mount")) - mount_point_ = std::string(current_mount_str); + mount_point_ = current_mount_str; else - mount_point_ = std::string("/"); + mount_point_ = "/"; if (const char* content_str = ptr->get_property("content")) content_.reset(parse_content(content_str)); diff --git a/src/plugins/host_dvfs.cpp b/src/plugins/host_dvfs.cpp index 9245029d21..2728cceef8 100644 --- a/src/plugins/host_dvfs.cpp +++ b/src/plugins/host_dvfs.cpp @@ -366,7 +366,7 @@ static void on_host_added(simgrid::s4u::Host& host) if (dynamic_cast(&host)) // Ignore virtual machines return; - std::string name = std::string("dvfs-daemon-") + host.get_cname(); + std::string name = "dvfs-daemon-" + host.get_name(); simgrid::s4u::ActorPtr daemon = simgrid::s4u::Actor::create(name.c_str(), &host, []() { /** * This lambda function is the function the actor (daemon) will execute @@ -379,7 +379,7 @@ static void on_host_added(simgrid::s4u::Host& host) std::string dvfs_governor; if (const char* host_conf = daemon_proc->get_host()->get_property("plugin/dvfs/governor")) { - dvfs_governor = std::string(host_conf); + dvfs_governor = host_conf; boost::algorithm::to_lower(dvfs_governor); } else { dvfs_governor = cfg_governor; diff --git a/src/plugins/host_energy.cpp b/src/plugins/host_energy.cpp index 6d9483d501..abb4fcdff5 100644 --- a/src/plugins/host_energy.cpp +++ b/src/plugins/host_energy.cpp @@ -216,10 +216,10 @@ HostEnergy::HostEnergy(simgrid::s4u::Host* ptr) : host_(ptr) const char* off_power_str = host_->get_property("wattage_off"); if (off_power_str != nullptr) { try { - this->watts_off_ = std::stod(std::string(off_power_str)); + this->watts_off_ = std::stod(off_power_str); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid value for property wattage_off of host ") + host_->get_cname() + - ": " + off_power_str); + throw std::invalid_argument("Invalid value for property wattage_off of host " + host_->get_name() + ": " + + off_power_str); } } /* watts_off is 0 by default */ diff --git a/src/plugins/link_energy.cpp b/src/plugins/link_energy.cpp index 51bd89c211..0c2a3ac8fb 100644 --- a/src/plugins/link_energy.cpp +++ b/src/plugins/link_energy.cpp @@ -110,13 +110,13 @@ void LinkEnergy::init_watts_range_list() try { idle_ = std::stod(current_power_values.front()); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid idle power value for link ") + this->link_->get_cname()); + throw std::invalid_argument("Invalid idle power value for link " + this->link_->get_name()); } try { busy_ = std::stod(current_power_values.back()); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid busy power value for link ") + this->link_->get_cname()); + throw std::invalid_argument("Invalid busy power value for link " + this->link_->get_name()); } } } diff --git a/src/plugins/link_energy_wifi.cpp b/src/plugins/link_energy_wifi.cpp index 5b46eb975f..8bfead7a22 100644 --- a/src/plugins/link_energy_wifi.cpp +++ b/src/plugins/link_energy_wifi.cpp @@ -214,7 +214,7 @@ void LinkEnergyWifi::init_watts_range_list() try { control_duration_ = std::stod(beacons_factor); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid beacons factor value for link ") + this->link_->get_cname()); + throw std::invalid_argument("Invalid beacons factor value for link " + this->link_->get_name()); } } @@ -237,22 +237,22 @@ void LinkEnergyWifi::init_watts_range_list() try { pSleep_ = std::stod(current_power_values.at(3)); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid idle power value for link ") + this->link_->get_cname()); + throw std::invalid_argument("Invalid idle power value for link " + this->link_->get_name()); } try { pRx_ = std::stod(current_power_values.at(2)); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid idle power value for link ") + this->link_->get_cname()); + throw std::invalid_argument("Invalid idle power value for link " + this->link_->get_name()); } try { pTx_ = std::stod(current_power_values.at(1)); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid idle power value for link ") + this->link_->get_cname()); + throw std::invalid_argument("Invalid idle power value for link " + this->link_->get_name()); } try { pIdle_ = std::stod(current_power_values.at(0)); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid busy power value for link ") + this->link_->get_cname()); + throw std::invalid_argument("Invalid busy power value for link " + this->link_->get_name()); } XBT_DEBUG("Values aa initialized with: pSleep=%f pIdle=%f pTx=%f pRx=%f", pSleep_, pIdle_, pTx_, pRx_); diff --git a/src/plugins/vm/VmLiveMigration.cpp b/src/plugins/vm/VmLiveMigration.cpp index 192c4b29fa..75f3a02228 100644 --- a/src/plugins/vm/VmLiveMigration.cpp +++ b/src/plugins/vm/VmLiveMigration.cpp @@ -27,7 +27,7 @@ void MigrationRx::operator()() bool received_finalize = false; std::string finalize_task_name = - std::string("__mig_stage3:") + vm_->get_cname() + "(" + src_pm_->get_cname() + "-" + dst_pm_->get_cname() + ")"; + "__mig_stage3:" + vm_->get_name() + "(" + src_pm_->get_name() + "-" + dst_pm_->get_name() + ")"; while (not received_finalize) { auto payload = mbox->get_unique(); @@ -72,7 +72,7 @@ void MigrationRx::operator()() } // Inform the SRC that the migration has been correctly performed auto* payload = new std::string("__mig_stage4:"); - *payload = *payload + vm_->get_cname() + "(" + src_pm_->get_cname() + "-" + dst_pm_->get_cname() + ")"; + *payload = *payload + vm_->get_name() + "(" + src_pm_->get_name() + "-" + dst_pm_->get_name() + ")"; mbox_ctl->put(payload, 0); @@ -333,10 +333,8 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) vm->start_migration(); - std::string rx_name = - std::string("__pr_mig_rx:") + vm->get_cname() + "(" + src_pm->get_cname() + "-" + dst_pm->get_cname() + ")"; - std::string tx_name = - std::string("__pr_mig_tx:") + vm->get_cname() + "(" + src_pm->get_cname() + "-" + dst_pm->get_cname() + ")"; + std::string rx_name = "__pr_mig_rx:" + vm->get_name() + "(" + src_pm->get_name() + "-" + dst_pm->get_name() + ")"; + std::string tx_name = "__pr_mig_tx:" + vm->get_name() + "(" + src_pm->get_name() + "-" + dst_pm->get_name() + ")"; simgrid::s4u::ActorPtr rx = simgrid::s4u::Actor::create(rx_name.c_str(), dst_pm, simgrid::plugin::vm::MigrationRx(vm, dst_pm)); @@ -347,8 +345,8 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm) /* wait until the migration have finished or on error has occurred */ XBT_DEBUG("wait for reception of the final ACK (i.e. migration has been correctly performed"); - simgrid::s4u::Mailbox* mbox_ctl = simgrid::s4u::Mailbox::by_name( - std::string("__mbox_mig_ctl:") + vm->get_cname() + "(" + src_pm->get_cname() + "-" + dst_pm->get_cname() + ")"); + simgrid::s4u::Mailbox* mbox_ctl = simgrid::s4u::Mailbox::by_name("__mbox_mig_ctl:" + vm->get_name() + "(" + + src_pm->get_name() + "-" + dst_pm->get_name() + ")"); mbox_ctl->get_unique(); tx->join(); rx->join(); diff --git a/src/plugins/vm/VmLiveMigration.hpp b/src/plugins/vm/VmLiveMigration.hpp index 26ed66c73a..c7880a33a2 100644 --- a/src/plugins/vm/VmLiveMigration.hpp +++ b/src/plugins/vm/VmLiveMigration.hpp @@ -38,10 +38,10 @@ public: { src_pm_ = vm_->get_pm(); - mbox_ctl = s4u::Mailbox::by_name(std::string("__mbox_mig_ctl:") + vm_->get_cname() + "(" + src_pm_->get_cname() + - "-" + dst_pm_->get_cname() + ")"); - mbox = s4u::Mailbox::by_name(std::string("__mbox_mig_src_dst:") + vm_->get_cname() + "(" + src_pm_->get_cname() + - "-" + dst_pm_->get_cname() + ")"); + mbox_ctl = s4u::Mailbox::by_name("__mbox_mig_ctl:" + vm_->get_name() + "(" + src_pm_->get_name() + "-" + + dst_pm_->get_name() + ")"); + mbox = s4u::Mailbox::by_name("__mbox_mig_src_dst:" + vm_->get_name() + "(" + src_pm_->get_name() + "-" + + dst_pm_->get_name() + ")"); } void operator()(); }; @@ -57,8 +57,8 @@ public: explicit MigrationTx(s4u::VirtualMachine* vm, s4u::Host* dst_pm) : vm_(vm), dst_pm_(dst_pm) { src_pm_ = vm_->get_pm(); - mbox = s4u::Mailbox::by_name(std::string("__mbox_mig_src_dst:") + vm_->get_cname() + "(" + src_pm_->get_cname() + - "-" + dst_pm_->get_cname() + ")"); + mbox = s4u::Mailbox::by_name("__mbox_mig_src_dst:" + vm_->get_name() + "(" + src_pm_->get_name() + "-" + + dst_pm_->get_name() + ")"); } void operator()(); sg_size_t sendMigrationData(sg_size_t size, int stage, int stage2_round, double mig_speed, double timeout); diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 8da467da70..5e5b04af45 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -208,7 +208,7 @@ Host* Engine::host_by_name(const std::string& name) const { auto* host = host_by_name_or_null(name); if (not host) - throw std::invalid_argument(std::string("Host not found: '") + name + std::string("'")); + throw std::invalid_argument("Host not found: '" + name + "'"); return host; } @@ -232,7 +232,7 @@ Link* Engine::link_by_name(const std::string& name) const { auto* link = link_by_name_or_null(name); if (not link) - throw std::invalid_argument(std::string("Link not found: ") + name); + throw std::invalid_argument("Link not found: " + name); return link; } @@ -240,7 +240,7 @@ SplitDuplexLink* Engine::split_duplex_link_by_name(const std::string& name) cons { auto* link_impl = pimpl->netzone_root_ ? pimpl->netzone_root_->get_split_duplex_link_by_name_or_null(name) : nullptr; if (not link_impl) - throw std::invalid_argument(std::string("Link not found: ") + name); + throw std::invalid_argument("Link not found: " + name); return link_impl->get_iface(); } @@ -396,7 +396,7 @@ kernel::routing::NetPoint* Engine::netpoint_by_name(const std::string& name) con { auto netp = netpoint_by_name_or_null(name); if (netp == nullptr) { - throw std::invalid_argument(std::string("Netpoint not found: %s") + name); + throw std::invalid_argument("Netpoint not found: " + name); } return netp; } diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 6f80d6e1f1..8a6cc71394 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -283,7 +283,7 @@ std::vector Host::convert_pstate_speed_vector(const std::vectorset_sharing_policy(policy, cb); }); return this; diff --git a/src/s4u/s4u_Netzone.cpp b/src/s4u/s4u_Netzone.cpp index 388cdd41ec..180eacdec0 100644 --- a/src/s4u/s4u_Netzone.cpp +++ b/src/s4u/s4u_Netzone.cpp @@ -170,8 +170,8 @@ s4u::SplitDuplexLink* NetZone::create_split_duplex_link(const std::string& name, try { speed = xbt_parse_get_bandwidth("", 0, bandwidth, ""); } catch (const simgrid::ParseError&) { - throw std::invalid_argument(std::string("Impossible to create split-duplex link: ") + name + - std::string(". Invalid bandwidth: ") + bandwidth); + throw std::invalid_argument("Impossible to create split-duplex link: " + name + + ". Invalid bandwidth: " + bandwidth); } return create_split_duplex_link(name, speed); } @@ -191,8 +191,7 @@ s4u::Link* NetZone::create_link(const std::string& name, const std::vectorget_cname(), get_cname()); - simgrid::s4u::Actor::create(get_cname() + std::string("-vm_destroy"), get_pm(), destroy_code); + simgrid::s4u::Actor::create(get_name() + "-vm_destroy", get_pm(), destroy_code); simgrid::s4u::this_actor::yield(); XBT_CRITICAL("I should be dead now!"); DIE_IMPOSSIBLE; diff --git a/src/smpi/bindings/smpi_pmpi.cpp b/src/smpi/bindings/smpi_pmpi.cpp index 543f451294..684b283a86 100644 --- a/src/smpi/bindings/smpi_pmpi.cpp +++ b/src/smpi/bindings/smpi_pmpi.cpp @@ -188,7 +188,7 @@ MPI_Aint PMPI_Aint_diff(MPI_Aint address, MPI_Aint disp) int PMPI_Get_processor_name(char *name, int *resultlen) { int len = std::min(static_cast(sg_host_self()->get_name().size()), MPI_MAX_PROCESSOR_NAME - 1); - std::string(sg_host_self()->get_name()).copy(name, len); + sg_host_self()->get_name().copy(name, len); name[len] = '\0'; *resultlen = len; diff --git a/src/smpi/bindings/smpi_pmpi_coll.cpp b/src/smpi/bindings/smpi_pmpi_coll.cpp index 1804c7319b..f83a8d3c4b 100644 --- a/src/smpi/bindings/smpi_pmpi_coll.cpp +++ b/src/smpi/bindings/smpi_pmpi_coll.cpp @@ -121,7 +121,7 @@ int PMPI_Igather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void } CHECK_ROOT(7) CHECK_REQUEST(9) - CHECK_COLLECTIVE(comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Gather" : "PMPI_Igather") + +" with root " + + CHECK_COLLECTIVE(comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Gather" : "PMPI_Igather") + " with root " + std::to_string(root)) const void* real_sendbuf = sendbuf; diff --git a/src/smpi/colls/smpi_automatic_selector.cpp b/src/smpi/colls/smpi_automatic_selector.cpp index 01c108ce8c..688e330da5 100644 --- a/src/smpi/colls/smpi_automatic_selector.cpp +++ b/src/smpi/colls/smpi_automatic_selector.cpp @@ -28,7 +28,7 @@ simgrid::instr::Container::get_root()->get_type()->by_name_or_create( \ _XBT_STRINGIFY(cat)); \ \ - std::string cont_name = std::string("rank-" + std::to_string(simgrid::s4u::this_actor::get_pid())); \ + std::string cont_name = "rank-" + std::to_string(simgrid::s4u::this_actor::get_pid()); \ type->add_entity_value(desc->name, "1.0 1.0 1.0"); \ new simgrid::instr::NewEvent(simgrid::s4u::Engine::get_clock(), simgrid::instr::Container::by_name(cont_name), \ type, type->get_entity_value(desc->name)); \ diff --git a/src/smpi/colls/smpi_coll.cpp b/src/smpi/colls/smpi_coll.cpp index 3d704cda57..973dd0b336 100644 --- a/src/smpi/colls/smpi_coll.cpp +++ b/src/smpi/colls/smpi_coll.cpp @@ -20,7 +20,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_coll, smpi, "Logging specific to SMPI colle namespace simgrid::smpi { std::map, std::less<>> smpi_coll_descriptions( - {{std::string("gather"), + {{"gather", {{"default", "gather default collective", (void*)gather__default}, {"ompi", "gather ompi collective", (void*)gather__ompi}, {"ompi_basic_linear", "gather ompi_basic_linear collective", (void*)gather__ompi_basic_linear}, diff --git a/src/smpi/include/smpi_datatype.hpp b/src/smpi/include/smpi_datatype.hpp index a2e404ebaf..fbf6a29c12 100644 --- a/src/smpi/include/smpi_datatype.hpp +++ b/src/smpi/include/smpi_datatype.hpp @@ -128,7 +128,7 @@ public: Datatype(const Datatype&) = delete; Datatype& operator=(const Datatype&) = delete; ~Datatype() override; - std::string name() const override {return name_.empty() ? std::string("MPI_Datatype") : name_;} + std::string name() const override { return name_.empty() ? "MPI_Datatype" : name_; } size_t size() const { return size_; } MPI_Aint lb() const { return lb_; } MPI_Aint ub() const { return ub_; } diff --git a/src/smpi/include/smpi_file.hpp b/src/smpi/include/smpi_file.hpp index 60ab2fde22..631d5cd5e4 100644 --- a/src/smpi/include/smpi_file.hpp +++ b/src/smpi/include/smpi_file.hpp @@ -44,7 +44,7 @@ class File : public F2C{ int flags() const; MPI_Datatype etype() const; MPI_Comm comm() const; - std::string name() const override {return file_ ? std::string("MPI_File: ")+ std::string(file_->get_path()): std::string("MPI_File");} + std::string name() const override { return file_ ? "MPI_File: " + std::string(file_->get_path()) : "MPI_File"; } int sync(); int seek(MPI_Offset offset, int whence); diff --git a/src/smpi/include/smpi_group.hpp b/src/smpi/include/smpi_group.hpp index aed599bea1..ed3cea6b70 100644 --- a/src/smpi/include/smpi_group.hpp +++ b/src/smpi/include/smpi_group.hpp @@ -34,7 +34,7 @@ public: void set_mapping(aid_t pid, int rank); int rank(aid_t pid) const; aid_t actor(int rank) const; - std::string name() const override {return std::string("MPI_Group");} + std::string name() const override { return "MPI_Group"; } void ref(); static void unref(MPI_Group group); int size() const { return static_cast(rank_to_pid_map_.size()); } diff --git a/src/smpi/include/smpi_info.hpp b/src/smpi/include/smpi_info.hpp index d40680166b..c3d8e4d437 100644 --- a/src/smpi/include/smpi_info.hpp +++ b/src/smpi/include/smpi_info.hpp @@ -25,7 +25,7 @@ public: static void unref(MPI_Info info); void set(const char* key, const char* value) { map_[key] = value; } int get(const char* key, int valuelen, char* value, int* flag) const; - std::string name() const override {return std::string("MPI_Info");} + std::string name() const override { return "MPI_Info"; } int remove(const char* key); int get_nkeys(int* nkeys) const; int get_nthkey(int n, char* key) const; diff --git a/src/smpi/include/smpi_request.hpp b/src/smpi/include/smpi_request.hpp index d63ed7b1e2..ba3292d401 100644 --- a/src/smpi/include/smpi_request.hpp +++ b/src/smpi/include/smpi_request.hpp @@ -67,7 +67,7 @@ public: int tag() const { return tag_; } int flags() const { return flags_; } bool detached() const { return detached_; } - std::string name() const override { return std::string("MPI_Request"); } + std::string name() const override { return "MPI_Request"; } MPI_Datatype type() const { return type_; } void print_request(const char* message) const; void start(); diff --git a/src/smpi/include/smpi_win.hpp b/src/smpi/include/smpi_win.hpp index ea8b9c47b7..6bcab2d3c2 100644 --- a/src/smpi/include/smpi_win.hpp +++ b/src/smpi/include/smpi_win.hpp @@ -56,7 +56,7 @@ public: int attach (void *base, MPI_Aint size); int detach (const void *base); void get_name(char* name, int* length) const; - std::string name() const override {return name_.empty() ? std::string("MPI_Win") : name_;} + std::string name() const override { return name_.empty() ? "MPI_Win" : name_; } void get_group( MPI_Group* group); void set_name(const char* name); int rank() const; diff --git a/src/smpi/internals/instr_smpi.cpp b/src/smpi/internals/instr_smpi.cpp index 335b79e27b..ea982cdc9a 100644 --- a/src/smpi/internals/instr_smpi.cpp +++ b/src/smpi/internals/instr_smpi.cpp @@ -96,7 +96,7 @@ static const char* instr_find_color(const char* c_state) XBT_PRIVATE simgrid::instr::Container* smpi_container(aid_t pid) { - return simgrid::instr::Container::by_name(std::string("rank-") + std::to_string(pid)); + return simgrid::instr::Container::by_name("rank-" + std::to_string(pid)); } static std::string TRACE_smpi_put_key(aid_t src, aid_t dst, int tag, int send) @@ -139,7 +139,7 @@ void TRACE_smpi_setup_container(aid_t pid, const_sg_host_t host) parent = simgrid::instr::Container::by_name_or_null(host->get_name()); xbt_assert(parent != nullptr, "Could not find a parent for mpi rank 'rank-%ld' at function %s", pid, __func__); } - parent->create_child(std::string("rank-") + std::to_string(pid), "MPI"); // This container is of type MPI + parent->create_child("rank-" + std::to_string(pid), "MPI"); // This container is of type MPI } void TRACE_smpi_init(aid_t pid, const std::string& calling_func) diff --git a/src/smpi/internals/smpi_replay.cpp b/src/smpi/internals/smpi_replay.cpp index 68570b3cbb..c192392a6e 100644 --- a/src/smpi/internals/smpi_replay.cpp +++ b/src/smpi/internals/smpi_replay.cpp @@ -186,7 +186,7 @@ void SleepParser::parse(simgrid::xbt::ReplayAction& action, const std::string&) void LocationParser::parse(simgrid::xbt::ReplayAction& action, const std::string&) { CHECK_ACTION_PARAMS(action, 2, 0) - filename = std::string(action[2]); + filename = action[2]; line = std::stoi(action[3]); } diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index 2aab0fffd9..0f84820dc2 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -185,9 +185,9 @@ std::string Comm::name() const std::array name; this->get_name(name.data(), &size); if (name[0]=='\0') - return std::string("MPI_Comm"); + return "MPI_Comm"; else - return std::string(name.data()); + return name.data(); } diff --git a/src/smpi/mpi/smpi_file.cpp b/src/smpi/mpi/smpi_file.cpp index 2b77328469..98f7ccf9e7 100644 --- a/src/smpi/mpi/smpi_file.cpp +++ b/src/smpi/mpi/smpi_file.cpp @@ -282,7 +282,7 @@ int File::set_view(MPI_Offset disp, MPI_Datatype etype, MPI_Datatype filetype, c { etype_ = etype; filetype_ = filetype; - datarep_ = std::string(datarep); + datarep_ = datarep; disp_ = disp; if (comm_->rank() == 0){ if(disp != MPI_DISPLACEMENT_CURRENT) diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index d64628809e..7b7175d441 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -40,7 +40,7 @@ HostImpl::~HostImpl() try { std::string actors; for (auto const& actor : actor_list_) - actors += "\n\t" + std::string(actor.get_name()); + actors += "\n\t" + actor.get_name(); EngineImpl::get_instance()->display_all_actor_status(); xbt_die("%s:%s", msg, actors.c_str()); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index f7f483788a..d78115a70c 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -149,7 +149,7 @@ sg_platf_cluster_create_host(const simgrid::kernel::routing::ClusterCreationArgs "(total = %zu). Check the 'radical' parameter in XML", cluster->id.c_str(), id, cluster->radicals.size()); - std::string host_id = std::string(cluster->prefix) + std::to_string(cluster->radicals[id]) + cluster->suffix; + std::string host_id = cluster->prefix + std::to_string(cluster->radicals[id]) + cluster->suffix; XBT_DEBUG("Cluster: creating host=%s speed=%f", host_id.c_str(), cluster->speeds.front()); const simgrid::s4u::Host* host = zone->create_host(host_id, cluster->speeds) ->set_core_count(cluster->core_amount) @@ -170,7 +170,7 @@ sg_platf_cluster_create_loopback(const simgrid::kernel::routing::ClusterCreation "(total = %zu). Check the 'radical' parameter in XML", cluster->id.c_str(), id, cluster->radicals.size()); - std::string link_id = std::string(cluster->id) + "_link_" + std::to_string(cluster->radicals[id]) + "_loopback"; + std::string link_id = cluster->id + "_link_" + std::to_string(cluster->radicals[id]) + "_loopback"; XBT_DEBUG("Cluster: creating loopback link=%s bw=%f", link_id.c_str(), cluster->loopback_bw); simgrid::s4u::Link* loopback = zone->create_link(link_id, cluster->loopback_bw) @@ -186,7 +186,7 @@ static simgrid::s4u::Link* sg_platf_cluster_create_limiter(const simgrid::kernel const std::vector& /*coord*/, unsigned long id) { - std::string link_id = std::string(cluster->id) + "_link_" + std::to_string(id) + "_limiter"; + std::string link_id = cluster->id + "_link_" + std::to_string(id) + "_limiter"; XBT_DEBUG("Cluster: creating limiter link=%s bw=%f", link_id.c_str(), cluster->limiter_link); simgrid::s4u::Link* limiter = zone->create_link(link_id, cluster->limiter_link)->seal(); @@ -250,7 +250,7 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA /* Make the backbone */ const simgrid::s4u::Link* backbone = nullptr; if ((cluster->bb_bw > 0) || (cluster->bb_lat > 0)) { - std::string bb_name = std::string(cluster->id) + "_backbone"; + std::string bb_name = cluster->id + "_backbone"; XBT_DEBUG(" ", bb_name.c_str(), cluster->bb_bw, cluster->bb_lat); @@ -261,7 +261,7 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA } for (int const& i : cluster->radicals) { - std::string host_id = std::string(cluster->prefix) + std::to_string(i) + cluster->suffix; + std::string host_id = cluster->prefix + std::to_string(i) + cluster->suffix; XBT_DEBUG("", host_id.c_str(), cluster->speeds.front()); const auto* host = zone->create_host(host_id, cluster->speeds) @@ -271,7 +271,7 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA XBT_DEBUG(""); - std::string link_id = std::string(cluster->id) + "_link_" + std::to_string(i); + std::string link_id = cluster->id + "_link_" + std::to_string(i); XBT_DEBUG("", link_id.c_str(), cluster->bw, cluster->lat); // add a loopback link @@ -291,7 +291,7 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA // add a limiter link (shared link to account for maximal bandwidth of the node) const simgrid::s4u::Link* limiter = nullptr; if (cluster->limiter_link > 0) { - std::string limiter_name = std::string(link_id) + "_limiter"; + std::string limiter_name = link_id + "_limiter"; XBT_DEBUG("", limiter_name.c_str(), cluster->limiter_link); limiter = zone->create_link(limiter_name, cluster->limiter_link)->seal(); @@ -320,7 +320,7 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA XBT_DEBUG(" "); XBT_DEBUG("", cluster->router_id.c_str()); if (cluster->router_id.empty()) - cluster->router_id = std::string(cluster->prefix) + cluster->id + "_router" + cluster->suffix; + cluster->router_id = cluster->prefix + cluster->id + "_router" + cluster->suffix; auto* router = zone->create_router(cluster->router_id); zone->add_route(router, nullptr, nullptr, nullptr, {}); diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index a46d4acd80..300bc16a56 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -26,7 +26,7 @@ XBT_PRIVATE std::unordered_map trace_connect_list_link void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* trace_connect) { surf_parse_assert(traces_set_list.find(trace_connect->trace) != traces_set_list.end(), - std::string("Cannot connect trace ") + trace_connect->trace + " to " + trace_connect->element + + "Cannot connect trace " + trace_connect->trace + " to " + trace_connect->element + ": trace unknown"); switch (trace_connect->kind) { @@ -46,7 +46,7 @@ void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* trace_connect_list_link_lat.try_emplace(trace_connect->trace, trace_connect->element); break; default: - surf_parse_error(std::string("Cannot connect trace ") + trace_connect->trace + " to " + trace_connect->element + + surf_parse_error("Cannot connect trace " + trace_connect->trace + " to " + trace_connect->element + ": unknown kind of trace"); } } @@ -68,51 +68,51 @@ void parse_platform_file(const std::string& file) /* connect all profiles relative to hosts */ for (auto const& [trace, name] : trace_connect_list_host_avail) { surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(), - std::string(": Trace ") + trace + " undefined."); + ": Trace " + trace + " undefined."); auto profile = traces_set_list.at(trace); auto host = engine->host_by_name_or_null(name); - surf_parse_assert(host, std::string(": Host ") + name + " undefined."); + surf_parse_assert(host, ": Host " + name + " undefined."); host->set_state_profile(profile); } for (auto const& [trace, name] : trace_connect_list_host_speed) { surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(), - std::string(": Trace ") + trace + " undefined."); + ": Trace " + trace + " undefined."); auto profile = traces_set_list.at(trace); auto host = engine->host_by_name_or_null(name); - surf_parse_assert(host, std::string(": Host ") + name + " undefined."); + surf_parse_assert(host, ": Host " + name + " undefined."); host->set_speed_profile(profile); } for (auto const& [trace, name] : trace_connect_list_link_avail) { surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(), - std::string(": Trace ") + trace + " undefined."); + ": Trace " + trace + " undefined."); auto profile = traces_set_list.at(trace); auto link = engine->link_by_name_or_null(name); - surf_parse_assert(link, std::string(": Link ") + name + " undefined."); + surf_parse_assert(link, ": Link " + name + " undefined."); link->set_state_profile(profile); } for (auto const& [trace, name] : trace_connect_list_link_bw) { surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(), - std::string(": Trace ") + trace + " undefined."); + ": Trace " + trace + " undefined."); auto profile = traces_set_list.at(trace); auto link = engine->link_by_name_or_null(name); - surf_parse_assert(link, std::string(": Link ") + name + " undefined."); + surf_parse_assert(link, ": Link " + name + " undefined."); link->set_bandwidth_profile(profile); } for (auto const& [trace, name] : trace_connect_list_link_lat) { surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(), - std::string(": Trace ") + trace + " undefined."); + ": Trace " + trace + " undefined."); auto profile = traces_set_list.at(trace); auto link = engine->link_by_name_or_null(name); - surf_parse_assert(link, std::string(": Link ") + name + " undefined."); + surf_parse_assert(link, ": Link " + name + " undefined."); link->set_latency_profile(profile); } diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 7d4239328a..93f87d0722 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -112,7 +112,7 @@ static void explodesRadical(const std::string& radicals, std::vector* explo end = surf_parse_get_int(radical_ends.back()); break; default: - surf_parse_error(std::string("Malformed radical: ") + group); + surf_parse_error("Malformed radical: " + group); } for (int i = start; i <= end; i++) exploded->push_back(i); @@ -198,7 +198,7 @@ void STag_surfxml_platform() { "available in the tools/ directory of the source archive."); surf_parse_assert( version >= 400L, - std::string("******* THIS FILE IS TOO OLD (v:") + version_string + + "******* THIS FILE IS TOO OLD (v:" + version_string + ") *********\n " "Changes introduced in SimGrid 3.13:\n" " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n" @@ -217,7 +217,7 @@ void STag_surfxml_platform() { "available in the tools/ directory of the source archive.", version_string.c_str(), surf_parsed_filename.c_str()); } - surf_parse_assert(version <= 410L, std::string("******* THIS FILE COMES FROM THE FUTURE (v:") + version_string + + surf_parse_assert(version <= 410L, "******* THIS FILE COMES FROM THE FUTURE (v:" + version_string + ") *********\n " "The most recent formalism that this version of SimGrid understands is v4.1.\n" "Please update your code, or use another, more adapted, file."); @@ -348,7 +348,7 @@ void ETag_surfxml_cluster(){ cluster.topology = simgrid::kernel::routing::ClusterTopology::DRAGONFLY; break; default: - surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id); + surf_parse_error("Invalid cluster topology for cluster " + cluster.id); } cluster.topo_parameters = A_surfxml_cluster_topo___parameters; cluster.router_id = A_surfxml_cluster_router___id; @@ -368,7 +368,7 @@ void ETag_surfxml_cluster(){ cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE; break; default: - surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id); + surf_parse_error("Invalid cluster sharing policy for cluster " + cluster.id); } switch (AX_surfxml_cluster_bb___sharing___policy) { case A_surfxml_cluster_bb___sharing___policy_FATPIPE: @@ -378,7 +378,7 @@ void ETag_surfxml_cluster(){ cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED; break; default: - surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id); + surf_parse_error("Invalid bb sharing policy in cluster " + cluster.id); } sg_platf_new_tag_cluster(&cluster); @@ -407,7 +407,7 @@ void STag_surfxml_cabinet(){ void STag_surfxml_peer(){ simgrid::kernel::routing::PeerCreationArgs peer; - peer.id = std::string(A_surfxml_peer_id); + peer.id = A_surfxml_peer_id; peer.speed = xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_speed, "speed of peer " + peer.id); peer.bw_in = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___in, @@ -443,7 +443,7 @@ void ETag_surfxml_link(){ link.properties = property_sets.back(); property_sets.pop_back(); - link.id = std::string(A_surfxml_link_id); + link.id = A_surfxml_link_id; link.bandwidths = xbt_parse_get_bandwidths(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_bandwidth, "bandwidth of link " + link.id); link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] @@ -476,7 +476,7 @@ void ETag_surfxml_link(){ link.policy = simgrid::s4u::Link::SharingPolicy::WIFI; break; default: - surf_parse_error(std::string("Invalid sharing policy in link ") + link.id); + surf_parse_error("Invalid sharing policy in link " + link.id); } sg_platf_new_link(&link); @@ -490,14 +490,14 @@ void STag_surfxml_link___ctn() switch (A_surfxml_link___ctn_direction) { case AU_surfxml_link___ctn_direction: case A_surfxml_link___ctn_direction_NONE: - link = engine->link_by_name(std::string(A_surfxml_link___ctn_id)); + link = engine->link_by_name(A_surfxml_link___ctn_id); break; case A_surfxml_link___ctn_direction_UP: - link = engine->split_duplex_link_by_name(std::string(A_surfxml_link___ctn_id)); + link = engine->split_duplex_link_by_name(A_surfxml_link___ctn_id); direction = simgrid::s4u::LinkInRoute::Direction::UP; break; case A_surfxml_link___ctn_direction_DOWN: - link = engine->split_duplex_link_by_name(std::string(A_surfxml_link___ctn_id)); + link = engine->split_duplex_link_by_name(A_surfxml_link___ctn_id); direction = simgrid::s4u::LinkInRoute::Direction::DOWN; break; default: @@ -523,7 +523,7 @@ void ETag_surfxml_backbone() { auto link = std::make_unique(); - link->id = std::string(A_surfxml_backbone_id); + link->id = A_surfxml_backbone_id; link->bandwidths.push_back(xbt_parse_get_bandwidth( surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_bandwidth, "bandwidth of backbone " + link->id)); link->latency = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_latency, @@ -839,7 +839,7 @@ void surf_parse_open(const std::string& file) surf_file_to_parse = surf_fopen(file, "r"); if (surf_file_to_parse == nullptr) - throw std::invalid_argument(std::string("Unable to open '") + file + "' from '" + simgrid::xbt::Path().get_name() + + throw std::invalid_argument("Unable to open '" + file + "' from '" + simgrid::xbt::Path().get_name() + "'. Does this file exist?"); surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE); surf_parse__switch_to_buffer(surf_input_buffer); diff --git a/src/xbt/backtrace.cpp b/src/xbt/backtrace.cpp index 7b44c9f4d1..7c09e5c5be 100644 --- a/src/xbt/backtrace.cpp +++ b/src/xbt/backtrace.cpp @@ -61,7 +61,7 @@ public: frame_name.find("simcall_run_answered") != std::string::npos || frame_name.find("simcall_run_blocking") != std::string::npos) { frame_count = 0; - ss.str(std::string()); // This is how you clear a stringstream in C++. clear() is something else :'( + ss.str(""); // This is how you clear a stringstream in C++. clear() is something else :'( } if (frame_name == "main") break; diff --git a/src/xbt/config.cpp b/src/xbt/config.cpp index 64c5b99ca2..694f8e2175 100644 --- a/src/xbt/config.cpp +++ b/src/xbt/config.cpp @@ -101,10 +101,7 @@ public: template <> class ConfigType { public: static constexpr const char* type_name = "string"; - static inline std::string parse(const char* value) - { - return std::string(value); - } + static inline std::string parse(const char* value) { return value; } }; template <> class ConfigType { public: diff --git a/src/xbt/log.cpp b/src/xbt/log.cpp index 916c77baf1..d4e4fdd01c 100644 --- a/src/xbt/log.cpp +++ b/src/xbt/log.cpp @@ -411,7 +411,7 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) throw std::invalid_argument(simgrid::xbt::string_printf("Unknown appender log type: '%s'", value)); } } else if (strncmp(option, "fmt", option_len) == 0) { - set.fmt = std::string(value); + set.fmt = value; } else { xbt_die("Unknown setting of the log category: '%.*s'", static_cast(option_len), option); } diff --git a/src/xbt/memory_map.cpp b/src/xbt/memory_map.cpp index 90e5c5f5d5..ceaf8d865c 100644 --- a/src/xbt/memory_map.cpp +++ b/src/xbt/memory_map.cpp @@ -202,7 +202,7 @@ std::vector get_memory_map(pid_t pid) #elif defined __linux__ /* Open the actual process's proc maps file and create the memory_map_t */ /* to be returned. */ - std::string path = std::string("/proc/") + std::to_string(pid) + "/maps"; + std::string path = "/proc/" + std::to_string(pid) + "/maps"; std::ifstream fp; fp.rdbuf()->pubsetbuf(nullptr, 0); fp.open(path); diff --git a/src/xbt/xbt_os_file.cpp b/src/xbt/xbt_os_file.cpp index fd280c9558..68817d56d7 100644 --- a/src/xbt/xbt_os_file.cpp +++ b/src/xbt/xbt_os_file.cpp @@ -28,22 +28,20 @@ simgrid::xbt::Path::Path() std::array buffer; const char* cwd = getcwd(buffer.data(), 2048); xbt_assert(cwd != nullptr, "Error during getcwd: %s", strerror(errno)); - path_ = std::string(cwd); + path_ = cwd; #else - path_ = std::string("."); + path_ = "."; #endif } std::string simgrid::xbt::Path::get_dir_name() const { std::string p(path_); - const char* res = dirname(&p[0]); - return std::string(res, strlen(res)); + return dirname(&p[0]); } std::string simgrid::xbt::Path::get_base_name() const { std::string p(path_); - const char* res = basename(&p[0]); - return std::string(res, strlen(res)); + return basename(&p[0]); } diff --git a/src/xbt/xbt_parse_units.cpp b/src/xbt/xbt_parse_units.cpp index 8a8929cb57..192d74e92f 100644 --- a/src/xbt/xbt_parse_units.cpp +++ b/src/xbt/xbt_parse_units.cpp @@ -62,9 +62,9 @@ static double xbt_parse_get_value_with_unit(const std::string& filename, int lin double res = strtod(string.c_str(), &endptr); const char* ptr = endptr; // for const-correctness if (errno == ERANGE) - throw simgrid::ParseError(filename, lineno, std::string("value out of range: ") + string); + throw simgrid::ParseError(filename, lineno, "value out of range: " + string); if (ptr == string) - throw simgrid::ParseError(filename, lineno, std::string("cannot parse number:") + string); + throw simgrid::ParseError(filename, lineno, "cannot parse number:" + string); if (ptr[0] == '\0') { // Ok, 0 can be unit-less if (res != 0 && not entity_kind.empty()) diff --git a/src/xbt/xbt_replay.cpp b/src/xbt/xbt_replay.cpp index f478b5ab66..4288a58157 100644 --- a/src/xbt/xbt_replay.cpp +++ b/src/xbt/xbt_replay.cpp @@ -52,7 +52,7 @@ bool ReplayReader::get(ReplayAction* action) static std::unique_ptr get_action(const char* name) { - if (auto queue_elt = action_queues.find(std::string(name)); queue_elt != action_queues.end()) { + if (auto queue_elt = action_queues.find(name); queue_elt != action_queues.end()) { if (auto& my_queue = queue_elt->second; not my_queue.empty()) { // Get something from my queue and return it auto action = std::move(my_queue.front()); @@ -154,7 +154,7 @@ int replay_runner(const char* actor_name, const char* trace_filename) */ void xbt_replay_action_register(const char* action_name, const action_fun& function) { - simgrid::xbt::action_funs[std::string(action_name)] = function; + simgrid::xbt::action_funs[action_name] = function; } /** @@ -165,7 +165,7 @@ void xbt_replay_action_register(const char* action_name, const action_fun& funct */ action_fun xbt_replay_action_get(const char* action_name) { - return simgrid::xbt::action_funs.at(std::string(action_name)); + return simgrid::xbt::action_funs.at(action_name); } void xbt_replay_set_tracefile(const std::string& filename) diff --git a/teshsuite/s4u/monkey-masterworkers/monkey-masterworkers.cpp b/teshsuite/s4u/monkey-masterworkers/monkey-masterworkers.cpp index b6334cf3b3..9554fc3e3e 100644 --- a/teshsuite/s4u/monkey-masterworkers/monkey-masterworkers.cpp +++ b/teshsuite/s4u/monkey-masterworkers/monkey-masterworkers.cpp @@ -108,7 +108,7 @@ int main(int argc, char* argv[]) "the only worker gets killed."); sg4::Host* master_host = rootzone->create_host("lilibeth 0", 1e9); // Host where the master will stay for (int i = 1; i < cfg_host_count; i++) { - auto hostname = std::string("lilibeth ") + std::to_string(i); + auto hostname = "lilibeth " + std::to_string(i); auto* host = rootzone->create_host(hostname, 1e9); sg4::LinkInRoute link(rootzone->create_link(hostname, "1MBps")->set_latency("24us")->seal()); rootzone->add_route(master_host->get_netpoint(), host->get_netpoint(), nullptr, nullptr, {link}, true); diff --git a/teshsuite/s4u/seal-platform/seal-platform.cpp b/teshsuite/s4u/seal-platform/seal-platform.cpp index e8b775bb34..7744647d07 100644 --- a/teshsuite/s4u/seal-platform/seal-platform.cpp +++ b/teshsuite/s4u/seal-platform/seal-platform.cpp @@ -21,8 +21,7 @@ public: /* Make a vector of the mailboxes to use */ std::vector mboxes; - std::string msg_content = - std::string("Hello, I'm alive and running on ") + std::string(sg4::this_actor::get_host()->get_name()); + std::string msg_content = "Hello, I'm alive and running on " + sg4::this_actor::get_host()->get_name(); for (const auto* host : hosts_) { auto* payload = new std::string(msg_content); /* Create a communication representing the ongoing communication, and store it in pending_comms */ @@ -93,7 +92,7 @@ int main(int argc, char* argv[]) sg4::Actor::create("sender", host_list[0], Sender(host_list)); /* create receiver in every host */ for (auto* host : host_list) { - sg4::Actor::create(std::string("receiver-") + std::string(host->get_name()), host, Receiver()); + sg4::Actor::create("receiver-" + host->get_name(), host, Receiver()); } /* runs the simulation */