From d02dbd433ce9e3f66bdc8b67f36a31d0f7b925fa Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Mon, 11 Feb 2019 20:45:12 +0100 Subject: [PATCH] Get rid of temporary vector of strings. Save the unnecessary cost of its construction. --- src/surf/sg_platf.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index bc82d2dd23..a3b956a687 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -111,31 +111,31 @@ simgrid::kernel::routing::NetPoint* sg_platf_new_router(std::string name, const return netpoint; } -void sg_platf_new_link(simgrid::kernel::routing::LinkCreationArgs* link) +static void sg_platf_new_link(simgrid::kernel::routing::LinkCreationArgs* link, const std::string& link_name) { - std::vector names; + simgrid::kernel::resource::LinkImpl* l = + surf_network_model->create_link(link_name, link->bandwidth, link->latency, link->policy); - if (link->policy == simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX) { - names.push_back(link->id+ "_UP"); - names.push_back(link->id+ "_DOWN"); - } else { - names.push_back(link->id); + if (link->properties) { + for (auto const& elm : *link->properties) + l->set_property(elm.first, elm.second); } - for (auto const& link_name : names) { - simgrid::kernel::resource::LinkImpl* l = - surf_network_model->create_link(link_name, link->bandwidth, link->latency, link->policy); - if (link->properties) { - for (auto const& elm : *link->properties) - l->set_property(elm.first, elm.second); - } + if (link->latency_trace) + l->set_latency_profile(link->latency_trace); + if (link->bandwidth_trace) + l->set_bandwidth_profile(link->bandwidth_trace); + if (link->state_trace) + l->set_state_profile(link->state_trace); +} - if (link->latency_trace) - l->set_latency_profile(link->latency_trace); - if (link->bandwidth_trace) - l->set_bandwidth_profile(link->bandwidth_trace); - if (link->state_trace) - l->set_state_profile(link->state_trace); +void sg_platf_new_link(simgrid::kernel::routing::LinkCreationArgs* link) +{ + if (link->policy == simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX) { + sg_platf_new_link(link, link->id + "_UP"); + sg_platf_new_link(link, link->id + "_DOWN"); + } else { + sg_platf_new_link(link, link->id); } delete link->properties; } -- 2.20.1