From b67343d6e9fc74fc159a51a48d0ea7d9a2374712 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 12 Mar 2019 10:42:03 +0100 Subject: [PATCH] Remove unnecessary calls to c_str(). --- src/kernel/routing/VivaldiZone.cpp | 4 ++-- src/surf/network_ns3.cpp | 2 +- src/surf/sg_platf.cpp | 2 +- src/surf/storage_n11.cpp | 8 +++++--- src/surf/xml/surfxml_parseplatf.cpp | 10 +++++----- src/surf/xml/surfxml_sax_cb.cpp | 2 +- teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp | 4 ++-- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/kernel/routing/VivaldiZone.cpp b/src/kernel/routing/VivaldiZone.cpp index 48a2ac9871..5eb06947e5 100644 --- a/src/kernel/routing/VivaldiZone.cpp +++ b/src/kernel/routing/VivaldiZone.cpp @@ -85,8 +85,8 @@ void VivaldiZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArg if (src->is_netzone()) { std::string srcName = "router_" + src->get_name(); std::string dstName = "router_" + dst->get_name(); - route->gw_src = simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(srcName.c_str()); - route->gw_dst = simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(dstName.c_str()); + route->gw_src = simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(srcName); + route->gw_dst = simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(dstName); } /* Retrieve the private links */ diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index d33067fb87..0a71792214 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -73,7 +73,7 @@ static void clusterCreation_cb(simgrid::kernel::routing::ClusterCreationArgs* cl // Create private link std::string host_id = cluster->prefix + std::to_string(i) + cluster->suffix; - NetPointNs3* host_src = sg_host_by_name(host_id.c_str())->pimpl_netpoint->extension(); + NetPointNs3* host_src = simgrid::s4u::Host::by_name(host_id)->pimpl_netpoint->extension(); xbt_assert(host_src, "Cannot find a NS3 host of name %s", host_id.c_str()); // Any NS3 route is symmetrical diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index dc1d5c30e3..5eac4b444f 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -636,7 +636,7 @@ void sg_platf_new_Zone_seal() /** @brief Add a link connecting a host to the rest of its AS (which must be cluster or vivaldi) */ void sg_platf_new_hostlink(simgrid::kernel::routing::HostLinkCreationArgs* hostlink) { - simgrid::kernel::routing::NetPoint* netpoint = sg_host_by_name(hostlink->id.c_str())->pimpl_netpoint; + simgrid::kernel::routing::NetPoint* netpoint = simgrid::s4u::Host::by_name(hostlink->id)->pimpl_netpoint; xbt_assert(netpoint, "Host '%s' not found!", hostlink->id.c_str()); xbt_assert(dynamic_cast(current_routing), "Only hosts from Cluster and Vivaldi ASes can get a host_link."); diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index 82aa54a851..f5508833bd 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -6,6 +6,7 @@ #include "storage_n11.hpp" #include "simgrid/kernel/routing/NetPoint.hpp" #include "simgrid/s4u/Engine.hpp" +#include "simgrid/s4u/Host.hpp" #include "src/kernel/lmm/maxmin.hpp" #include "src/surf/xml/platf.hpp" #include "surf/surf.hpp" @@ -20,12 +21,13 @@ extern std::map storage_ty void check_disk_attachment() { for (auto const& s : simgrid::s4u::Engine::get_instance()->get_all_storages()) { - simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s->get_impl()->getHost().c_str()); + simgrid::kernel::routing::NetPoint* host_elm = + simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(s->get_impl()->getHost()); if (not host_elm) surf_parse_error(std::string("Unable to attach storage ") + s->get_cname() + ": host " + - s->get_impl()->getHost().c_str() + " does not exist."); + s->get_impl()->getHost() + " does not exist."); else - s->set_host(sg_host_by_name(s->get_impl()->getHost().c_str())); + s->set_host(simgrid::s4u::Host::by_name(s->get_impl()->getHost())); } } diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index 739247afcf..8fb038afa6 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -105,7 +105,7 @@ void parse_platform_file(const std::string& file) xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); simgrid::kernel::profile::Profile* profile = traces_set_list.at(elm.first); - simgrid::s4u::Host* host = sg_host_by_name(elm.second.c_str()); + simgrid::s4u::Host* host = simgrid::s4u::Host::by_name_or_null(elm.second); xbt_assert(host, "Host %s undefined", elm.second.c_str()); simgrid::surf::Cpu* cpu = host->pimpl_cpu; @@ -116,7 +116,7 @@ void parse_platform_file(const std::string& file) xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); simgrid::kernel::profile::Profile* profile = traces_set_list.at(elm.first); - simgrid::s4u::Host* host = sg_host_by_name(elm.second.c_str()); + simgrid::s4u::Host* host = simgrid::s4u::Host::by_name_or_null(elm.second); xbt_assert(host, "Host %s undefined", elm.second.c_str()); simgrid::surf::Cpu* cpu = host->pimpl_cpu; @@ -127,7 +127,7 @@ void parse_platform_file(const std::string& file) xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); simgrid::kernel::profile::Profile* profile = traces_set_list.at(elm.first); - sg_link_t link = simgrid::s4u::Link::by_name(elm.second.c_str()); + sg_link_t link = simgrid::s4u::Link::by_name(elm.second); xbt_assert(link, "Link %s undefined", elm.second.c_str()); link->set_state_profile(profile); } @@ -135,7 +135,7 @@ void parse_platform_file(const std::string& file) for (auto const& elm : trace_connect_list_link_bw) { xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); simgrid::kernel::profile::Profile* profile = traces_set_list.at(elm.first); - sg_link_t link = simgrid::s4u::Link::by_name(elm.second.c_str()); + sg_link_t link = simgrid::s4u::Link::by_name(elm.second); xbt_assert(link, "Link %s undefined", elm.second.c_str()); link->set_bandwidth_profile(profile); } @@ -143,7 +143,7 @@ void parse_platform_file(const std::string& file) for (auto const& elm : trace_connect_list_link_lat) { xbt_assert(traces_set_list.find(elm.first) != traces_set_list.end(), "Trace %s undefined", elm.first.c_str()); simgrid::kernel::profile::Profile* profile = traces_set_list.at(elm.first); - sg_link_t link = simgrid::s4u::Link::by_name(elm.second.c_str()); + sg_link_t link = simgrid::s4u::Link::by_name(elm.second); xbt_assert(link, "Link %s undefined", elm.second.c_str()); link->set_latency_profile(profile); } diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 4465820a78..26046c6b5e 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -53,7 +53,7 @@ void surf_parse_error(const std::string& msg) void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre, const std::string& post) { - if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found + if (simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(hostname) != nullptr) // found return; std::string msg = pre + hostname + post + " Existing netpoints: \n"; diff --git a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp index e26d0f0f89..bc625c957f 100644 --- a/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp +++ b/teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp @@ -49,7 +49,7 @@ static void sender(std::vector args) for (unsigned int test = 1; test <= args[0].size(); test++) { simgrid::s4u::this_actor::sleep_until(test * 5 - 5); std::string* mboxName = new std::string("Test #" + std::to_string(test)); - simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::by_name(mboxName->c_str()); + simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::by_name(*mboxName); switch (args[0][test - 1]) { case 'r': @@ -96,7 +96,7 @@ static void receiver(std::vector args) for (unsigned int test = 1; test <= args[0].size(); test++) { simgrid::s4u::this_actor::sleep_until(test * 5 - 5); std::string mboxName = "Test #" + std::to_string(test); - simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::by_name(mboxName.c_str()); + simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::by_name(mboxName); void* received = nullptr; switch (args[0][test - 1]) { -- 2.20.1